The Enormous Sequence

Define a_n by summing every nonempty subset sum of the first n-1 terms, then answer queries about gcd, 2-adic valuation of lcm, prefix sums, or a single term for various starting values.

Hard9MathNumber theoryCombinatoricsPrefix sumNo attempts yetTime limit2sMemory limit128 MB

Problem

Fibonacci numbers grow fast. Taekhee wrote them on paper all the way to the millionth term and still was not satisfied, so he defined a sequence of his own that grows much faster.

The first term is a1=ka_1 = k. With Nn={1,2,3,,n}N_n = \{1, 2, 3, \dots, n\}, the next term is given by

an+1=SNniSaia_{n+1} = \sum_{\emptyset \ne S \subseteq N_n} \sum_{i \in S} a_i

In other words, for every way of choosing at least one term among a1a_1 through ana_n, take the sum of the chosen terms, and an+1a_{n+1} is the total of all those sums.

For a1=1a_1 = 1 the first few terms are

  • a2=(a1)=1a_2 = (a_1) = 1
  • a3=(a1)+(a2)+(a1+a2)=4a_3 = (a_1) + (a_2) + (a_1 + a_2) = 4
  • a4=(a1)+(a2)+(a3)+(a1+a2)+(a1+a3)+(a2+a3)+(a1+a2+a3)=24a_4 = (a_1) + (a_2) + (a_3) + (a_1 + a_2) + (a_1 + a_3) + (a_2 + a_3) + (a_1 + a_2 + a_3) = 24

Taekhee prepared QQ questions about this sequence. Each question comes with its own first term a1a_1, so each question is about its own sequence. Write a program that answers all of them.

Input

The first line contains the number of questions QQ. (1Q2000001 \le Q \le 200000)

Each of the next QQ lines contains one question in one of the four forms below.

  • 1 a1 i j (1a11051 \le a_1 \le 10^5, 1i,j1061 \le i, j \le 10^6): in the sequence whose first term is a1a_1, what is the greatest common divisor of aia_i and aja_j?
  • 2 a1 i j (1a11051 \le a_1 \le 10^5, 1i,j1061 \le i, j \le 10^6): in the sequence whose first term is a1a_1, let LL be the least common multiple of aia_i and aja_j. That value is far too large, so the question asks for the largest integer PP such that L2P\frac{L}{2^P} is an integer.
  • 3 a1 i j (1a11051 \le a_1 \le 10^5, 1i,j1061 \le i, j \le 10^6): in the sequence whose first term is a1a_1, what is k=ijak\sum_{k=i}^{j} a_k? A question of this form always satisfies iji \le j.
  • 4 a1 k (1a11051 \le a_1 \le 10^5, 1k1061 \le k \le 10^6): in the sequence whose first term is a1a_1, what is aka_k?

Output

Print QQ lines. On each line print the answer to the corresponding question modulo 1,000,000,007, in the order the questions are given.