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;
const int N = 100100, P = 1000000007;
int i, j, k, n, m, ch, o, x, nls, ans;
int a[N], Ls[N], cnt[N], st[N], vl[N], vr[N], rk[N], p[N], z[N], Tr[N];
struct tree {
  tree *l, *r;
  int sum, num, sm2, ad;
} T[N << 3], *cur, *rta[N], *rtb[N];
void R(int &x) {
  x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
void W(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) W(x / 10);
  putchar(x % 10 + '0');
}
int find(int x) {
  int l = 1, r = nls, mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if (Ls[mid] == x) return mid;
    if (Ls[mid] < x)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return l;
}
void T_add(int x, int y) {
  for (; x <= n; x += x & -x) Tr[x] = (Tr[x] + y) % P;
}
int T_query(int x) {
  int y = 0;
  for (; x; x -= x & -x) y = (y + Tr[x]) % P;
  return y;
}
void up(tree *k) {
  k->sum = (k->l->sum + k->r->sum) % P;
  k->num = (k->l->num + k->r->num) % P;
  k->sm2 = (k->l->sm2 + k->r->sm2) % P;
}
void down(tree *k) {
  if (k->ad) {
    k->l->ad = (k->l->ad + k->ad) % P;
    k->l->sm2 = ((long long)k->l->sum * k->ad + k->l->sm2) % P;
    k->r->ad = (k->r->ad + k->ad) % P;
    k->r->sm2 = ((long long)k->r->sum * k->ad + k->r->sm2) % P;
    k->ad = 0;
  }
}
void Ta_build(int L, int R, tree *&k) {
  k = ++cur;
  k->l = k->r = T;
  k->sum = k->num = k->sm2 = k->ad = 0;
  if (L == R) {
    k->sum = vl[p[st[i] + L]];
    k->num = 1;
    k->sm2 = (long long)vl[p[st[i] + L]] * (cnt[i] - L) % P;
    return;
  }
  int mid = (L + R) >> 1;
  Ta_build(L, mid, k->l);
  Ta_build(mid + 1, R, k->r);
  up(k);
}
void Tb_build(int L, int R, tree *&k) {
  k = ++cur;
  k->l = k->r = T;
  k->sum = k->num = k->sm2 = k->ad = 0;
  if (L == R) {
    k->sum = vr[p[st[i] + L]];
    k->num = 1;
    k->sm2 = (long long)vr[p[st[i] + L]] * (L - 1) % P;
    return;
  }
  int mid = (L + R) >> 1;
  Tb_build(L, mid, k->l);
  Tb_build(mid + 1, R, k->r);
  up(k);
}
int T_sum(int L, int R, int l, int r, tree *k) {
  if (l > r) return 0;
  if (L == l && R == r) return k->sum;
  down(k);
  int mid = (L + R) >> 1;
  if (r <= mid) return T_sum(L, mid, l, r, k->l);
  if (l > mid) return T_sum(mid + 1, R, l, r, k->r);
  return (T_sum(L, mid, l, mid, k->l) + T_sum(mid + 1, R, mid + 1, r, k->r)) %
         P;
}
int T_num(int L, int R, int l, int r, tree *k) {
  if (l > r) return 0;
  if (L == l && R == r) return k->num;
  down(k);
  int mid = (L + R) >> 1;
  if (r <= mid) return T_num(L, mid, l, r, k->l);
  if (l > mid) return T_num(mid + 1, R, l, r, k->r);
  return (T_num(L, mid, l, mid, k->l) + T_num(mid + 1, R, mid + 1, r, k->r)) %
         P;
}
int T_sm2(int L, int R, int l, int r, tree *k) {
  if (l > r) return 0;
  if (L == l && R == r) return k->sm2;
  down(k);
  int mid = (L + R) >> 1;
  if (r <= mid) return T_sm2(L, mid, l, r, k->l);
  if (l > mid) return T_sm2(mid + 1, R, l, r, k->r);
  return (T_sm2(L, mid, l, mid, k->l) + T_sm2(mid + 1, R, mid + 1, r, k->r)) %
         P;
}
void T_change0(int L, int R, int x, tree *k) {
  if (L == R) {
    k->num = 0;
    k->sum = 0;
    k->sm2 = 0;
    return;
  }
  down(k);
  int mid = (L + R) >> 1;
  if (x <= mid)
    T_change0(L, mid, x, k->l);
  else
    T_change0(mid + 1, R, x, k->r);
  up(k);
}
void T_change1(int L, int R, int x, int t1, int t2, tree *k) {
  if (L == R) {
    k->num = 1;
    k->sum = t1;
    k->sm2 = t2;
    return;
  }
  down(k);
  int mid = (L + R) >> 1;
  if (x <= mid)
    T_change1(L, mid, x, t1, t2, k->l);
  else
    T_change1(mid + 1, R, x, t1, t2, k->r);
  up(k);
}
void T_add(int L, int R, int l, int r, int ad, tree *k) {
  if (l > r) return;
  if (L == l && R == r) {
    k->ad = (k->ad + ad) % P;
    k->sm2 = ((long long)k->sum * ad + k->sm2) % P;
    return;
  }
  down(k);
  int mid = (L + R) >> 1;
  if (r <= mid)
    T_add(L, mid, l, r, ad, k->l);
  else {
    if (l > mid)
      T_add(mid + 1, R, l, r, ad, k->r);
    else
      T_add(L, mid, l, mid, ad, k->l), T_add(mid + 1, R, mid + 1, r, ad, k->r);
  }
  up(k);
}
int main() {
  cur = T;
  R(n);
  for (i = 1; i <= n; i++) R(a[i]), Ls[i] = a[i];
  sort(Ls + 1, Ls + n + 1);
  Ls[n + 1] = -1;
  for (i = 1; i <= n; i++)
    if (Ls[i] != Ls[i + 1]) Ls[++nls] = Ls[i];
  for (i = 1; i <= n; i++) {
    a[i] = find(a[i]);
    cnt[a[i]]++;
    rk[i] = cnt[a[i]];
  }
  for (i = 1; i <= nls; i++) st[i] = st[i - 1] + cnt[i - 1];
  for (i = 1; i <= n; i++) {
    vl[i] = T_query(a[i]);
    T_add(a[i], 1);
  }
  for (i = 1; i <= nls; i++) Tr[i] = 0;
  for (i = n; i; i--) {
    vr[i] = T_query(a[i]);
    T_add(a[i], 1);
  }
  for (i = 1; i <= n; i++) p[st[a[i]] + rk[i]] = i;
  for (i = 1; i <= nls; i++)
    Ta_build(1, cnt[i], rta[i]), Tb_build(1, cnt[i], rtb[i]);
  for (i = 1; i <= n; i++) {
    int suma = T_sum(1, cnt[a[i]], 1, rk[i] - 1, rta[a[i]]),
        sumb = T_sum(1, cnt[a[i]], rk[i] + 1, cnt[a[i]], rtb[a[i]]);
    ans = ((long long)suma * sumb + ans) % P;
  }
  R(m);
  for (i = 1; i <= m; i++) {
    R(o);
    R(x);
    if (o == 1) {
      if (!z[x]) {
        z[x] = 1;
        int numa = T_num(1, cnt[a[x]], rk[x], cnt[a[x]], rta[a[x]]),
            numb = T_num(1, cnt[a[x]], 1, rk[x], rtb[a[x]]);
        int suma = T_sum(1, cnt[a[x]], 1, rk[x] - 1, rta[a[x]]),
            sumb = T_sum(1, cnt[a[x]], rk[x] + 1, cnt[a[x]], rtb[a[x]]);
        int sm2a = T_sm2(1, cnt[a[x]], 1, rk[x] - 1, rta[a[x]]),
            sm2b = T_sm2(1, cnt[a[x]], rk[x] + 1, cnt[a[x]], rtb[a[x]]);
        int ta = (sm2a + P - (long long)numa * suma % P) % P,
            tb = (sm2b + P - (long long)numb * sumb % P) % P;
        ans = (ans + P - (long long)suma * sumb % P) % P;
        ans =
            (ans + P - ((long long)ta * vr[x] + (long long)tb * vl[x]) % P) % P;
        T_change0(1, cnt[a[x]], rk[x], rta[a[x]]);
        T_change0(1, cnt[a[x]], rk[x], rtb[a[x]]);
        T_add(1, cnt[a[x]], 1, rk[x] - 1, P - 1, rta[a[x]]);
        T_add(1, cnt[a[x]], rk[x] + 1, cnt[a[x]], P - 1, rtb[a[x]]);
      }
    } else {
      if (z[x]) {
        z[x] = 0;
        int numa = T_num(1, cnt[a[x]], rk[x], cnt[a[x]], rta[a[x]]),
            numb = T_num(1, cnt[a[x]], 1, rk[x], rtb[a[x]]);
        int suma = T_sum(1, cnt[a[x]], 1, rk[x] - 1, rta[a[x]]),
            sumb = T_sum(1, cnt[a[x]], rk[x] + 1, cnt[a[x]], rtb[a[x]]);
        int sm2a = T_sm2(1, cnt[a[x]], 1, rk[x] - 1, rta[a[x]]),
            sm2b = T_sm2(1, cnt[a[x]], rk[x] + 1, cnt[a[x]], rtb[a[x]]);
        int ta = (sm2a + P - (long long)numa * suma % P) % P,
            tb = (sm2b + P - (long long)numb * sumb % P) % P;
        ans = (ans + (long long)suma * sumb) % P;
        ans = (ans + (long long)ta * vr[x] + (long long)tb * vl[x]) % P;
        T_change1(1, cnt[a[x]], rk[x], vl[x], (long long)vl[x] * numa % P,
                  rta[a[x]]);
        T_change1(1, cnt[a[x]], rk[x], vr[x], (long long)vr[x] * numb % P,
                  rtb[a[x]]);
        T_add(1, cnt[a[x]], 1, rk[x] - 1, 1, rta[a[x]]);
        T_add(1, cnt[a[x]], rk[x] + 1, cnt[a[x]], 1, rtb[a[x]]);
      }
    }
    W(ans);
    puts("");
  }
}