Problem: On the 228-th international Uzhlyandian Wars strategic game tournament teams from each country are called. The teams should consist of 5 participants.

The team of Uzhlyandia will consist of soldiers, because there are no gamers.

Masha is a new minister of defense and gaming. The prime duty of the minister is to calculate the efficiency of the Uzhlandian army. The army consists of n soldiers standing in a row, enumerated from 1 to n. For each soldier we know his skill in Uzhlyandian Wars: the i-th soldier's skill is ai.

It was decided that the team will consist of three players and two assistants. The skills of players should be same, and the assistants' skills should not be greater than the players' skill. Moreover, it is important for Masha that one of the assistants should stand in the row to the left of the players, and the other one should stand in the row to the right of the players. Formally, a team is five soldiers with indexes i, j, k, l, p, such that 1 ≤ i < j < k < l < p ≤ n and ai ≤ aj = ak = al ≥ ap. 

The efficiency of the army is the number of different teams Masha can choose. Two teams are considered different if there is such i such that the i-th soldier is a member of one team, but not a member of the other team.

Initially, all players are able to be players. For some reasons, sometimes some soldiers become unable to be players. Sometimes some soldiers, that were unable to be players, become able to be players. At any time any soldier is able to be an assistant. Masha wants to control the efficiency of the army, so she asked you to tell her the number of different possible teams modulo 1000000007 (109 + 7) after each change. 

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of soldiers in Uzhlyandia.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the soldiers' skills.

The third line contains single integer m (1 ≤ m ≤ 105) — the number of changes.

The next m lines contain the changes, each change is described with two integers t and x (1 ≤ t ≤ 2, 1 ≤ x ≤ n) on a separate line. If t = 1, then the x-th soldier is unable to be a player after this change. If t = 2, then the x-th soldier is able to be a player after this change. 

It is guaranteed that before each query of the first type the soldier is able to be a player, and before each query of the second type the soldier is unable to be a player.

Output

Print m integers — the number of distinct teams after each change.

Print the answers modulo 1000000007 (109 + 7). 

Examples

Input

6
1 1 1 1 1 1
2
1 3
2 3


Output

1
6


Input

8
3 4 4 2 4 5 4 1
3
1 5
2 5
1 2


Output

1
6
2

Note

In the first example, after the first change the only team consists of soldiers [1, 2, 4, 5, 6]. After the second change any five soldiers can form a team.

In the first example after the first change the only team is soldiers [1, 2, 3, 7, 8]. After the second change the possible teams are: [1, 2, 3, 5, 7], [1, 2, 3, 5, 8], [1, 2, 3, 7, 8], [1, 2, 5, 7, 8], [1, 3, 5, 7, 8], [2, 3, 5, 7, 8]. After the third change the possible teams are: [1, 3, 5, 7, 8], [2, 3, 5, 7, 8].

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
class segtree {
 public:
  int seg[524288 * 2][6][6];
  long long e[6][6];
  long long now[6];
  void tim(int node) {
    long long x[6];
    fill(x, x + 6, 0);
    for (int i = 0; i < 6; i++)
      for (int j = i; j < 6; j++) x[j] += now[i] * seg[node][i][j];
    for (int i = 0; i < 6; i++) now[i] = x[i] % mod;
  }
  void merge(int node) {
    long long x[6][6];
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++) x[i][j] = 0;
    for (int i = 0; i < 6; i++)
      for (int j = i; j < 6; j++)
        for (int k = j; k < 6; k++)
          x[i][k] += (long long)seg[node * 2][i][j] *
                     (long long)seg[node * 2 + 1][j][k];
    for (int i = 0; i < 6; i++)
      for (int j = i; j < 6; j++) seg[node][i][j] = x[i][j] % mod;
  }
  void initv(int node, int t) {
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++) seg[node][i][j] = e[i][j];
    if (t >= 0)
      seg[node][0][1] = seg[node][4][5] = t;
    else
      for (int i = 0; i < 5; i++) seg[node][i][i + 1]++;
  }
  void init(vector<long long> vec) {
    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++) e[i][j] = (i == j);
    for (int i = 0; i < vec.size(); i++) initv(i + 524288, vec[i]);
    for (int i = vec.size(); i < 524288; i++) initv(i + 524288, 0);
    for (int i = 524288 - 1; i >= 1; i--) merge(i);
  }
  void update(int a, int b) {
    a += 524288;
    initv(a, b);
    for (;;) {
      a >>= 1;
      merge(a);
      if (a == 1) break;
    }
  }
  void get(int beg, int end, int node, int lb, int ub) {
    if (beg <= lb && ub <= end) {
      tim(node);
      return;
    }
    if (beg <= (lb + ub) / 2) get(beg, end, node * 2, lb, (lb + ub) / 2);
    if ((lb + ub) / 2 + 1 <= end)
      get(beg, end, node * 2 + 1, (lb + ub) / 2 + 1, ub);
  }
  long long q(int beg, int end) {
    fill(now, now + 6, 0);
    now[0] = 1;
    get(beg, end, 1, 0, 524288 - 1);
    return now[5];
  }
};
segtree tree;
class BIT {
 public:
  int bit[524288 + 1];
  void add(int a, int b) {
    a += 5;
    for (;;) {
      bit[a] += b;
      a += a & -a;
      if (a > 524288) return;
    }
  }
  int get(int a) {
    a += 5;
    int ret = 0;
    for (;;) {
      ret += bit[a];
      a -= a & -a;
      if (a == 0) return ret;
    }
  }
};
BIT bi;
int dat[100000];
int zat[100000];
vector<int> now[100000];
int lb[100000];
int ub[100000];
int main() {
  int num;
  scanf("%d", &num);
  for (int i = 0; i < num; i++) scanf("%d", &dat[i]), zat[i] = dat[i];
  sort(zat, zat + num);
  for (int i = 0; i < num; i++)
    now[lower_bound(zat, zat + num, dat[i]) - zat].push_back(i);
  vector<long long> ret;
  for (int i = 0; i < num; i++) {
    lb[i] = ret.size();
    int bef = -1;
    for (int j = 0; j < now[i].size(); j++) {
      ret.push_back(bi.get(now[i][j]) - bi.get(bef));
      bef = now[i][j];
      ret.push_back(-1);
    }
    ret.push_back(bi.get(num) - bi.get(bef));
    for (int j = 0; j < now[i].size(); j++) bi.add(now[i][j], 1);
    ub[i] = int(ret.size()) - 1;
  }
  tree.init(ret);
  long long ans = 0;
  for (int i = 0; i < num; i++) ans += tree.q(lb[i], ub[i]);
  int query;
  scanf("%d", &query);
  for (int p = 0; p < query; p++) {
    int za, zb;
    scanf("%d%d", &za, &zb);
    zb--;
    int low = lower_bound(zat, zat + num, dat[zb]) - zat;
    int idx =
        lower_bound(now[low].begin(), now[low].end(), zb) - now[low].begin();
    ans -= tree.q(lb[low], ub[low]);
    if (za == 1)
      tree.update(lb[low] + idx * 2 + 1, 1);
    else
      tree.update(lb[low] + idx * 2 + 1, -1);
    ans += tree.q(lb[low], ub[low]);
    printf("%I64d\n", ans % mod);
  }
}