PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000370. Ước chung lớn nhất của mảng (GCD of an Array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Ước chung lớn nhất của mảng (GCD of an Array)

GCD of an Array

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n and qq operations performed in order. An operation provides i,xi,x and replaces aia_i by ai⋅xa_i\cdot x, leaving every other element unchanged.

After each operation, find gcd⁡(a1,a2,…,an)\gcd(a_1,a_2,\ldots,a_n). Array elements may become extremely large, so output only the answer modulo 109+710^9+7.

For example, starting with [1,6,8,12][1,6,8,12], multiplying the first element by 1212 gives [12,6,8,12][12,6,8,12], whose GCD is 22. Multiplying the second element by 33 leaves the GCD equal to 22. Multiplying the third element by 33 then makes the GCD equal to 66.

Important: Do not reduce individual array elements modulo 109+710^9+7 before computing their GCD. The modulus is applied only to the reported answer.

Input

The first line contains n,qn,q. The second line contains nn values aia_i. Each of the next qq lines contains i,xi,x, where indices are 11-based.

Output

Print exactly qq lines. Line jj is the GCD after operation jj, modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n,q≤2 0001\le n,q\le 2\,000; 1≤ai,x≤1 0001\le a_i,x\le 1\,000; 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n,q≤50 0001\le n,q\le 50\,000; 1≤ai,x≤100 0001\le a_i,x\le 100\,000; 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n,q≤200 0001\le n,q\le 200\,000; 1≤ai,x≤200 0001\le a_i,x\le 200\,000; 1≤i≤n1\le i\le n.

Examples

Example 1

Input

4 3
1 6 8 12
1 12
2 3
3 3

Output

2
2
6

Explanation

The arrays after the three operations are [12,6,8,12][12,6,8,12], [12,18,8,12][12,18,8,12], and [12,18,24,12][12,18,24,12]; their GCDs are 2,2,62,2,6.