A combination lock requires three selections of numbers, each from 1 through 39. Suppose the lock is constructed in such a way that no number can be used twice in a row but the same number may occur both first and third. For example, 20 13 20 would be acceptable, but 20 20 13 would not. How many different combinations are possible?