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;
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  if (p1 == p2) {
    p2 = (p1 = buf) + fread(buf, 1, 100000, stdin);
    if (p1 == p2) return EOF;
  }
  return *p1++;
}
inline void Read(int& x) {
  char c = nc();
  for (; c < '0' || c > '9'; c = nc())
    ;
  for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - 48, c = nc())
    ;
}
int Len;
char ss[30];
inline void Print(int x) {
  if (!x) {
    putchar(48);
    putchar('\n');
    return;
  }
  for (Len = 0; x; x /= 10) ss[++Len] = x % 10;
  while (Len) putchar(ss[Len--] + 48);
  putchar('\n');
}
struct Node {
  int l, r, w[5], p[2];
} c[100010 << 2];
struct Disc {
  int w, f;
} d[100010];
vector<int> g[100010];
int i, j, k, n, m, a[100010], s1[100010], s2[100010], b[100010], Num,
    Rt[100010], f[100010], s[100010], Ans, Q, x, y, S, t;
inline bool Cmp(Disc a, Disc b) { return a.w < b.w; }
inline void Update1(int x) {
  for (; x <= m; x += x & -x) b[x]++;
}
inline int Query1(int x) {
  int Ans = 0;
  for (; x; x -= x & -x) Ans += b[x];
  return Ans;
}
inline void Update_sum(int x, int y, int d) {
  c[x].w[d + 2] =
      (c[x].w[d + 2] + 1ll * y * c[x].w[d] % 1000000007) % 1000000007;
  c[x].p[d] += y;
}
inline void Up(int x) {
  for (int i = 0; i < 5; i++)
    c[x].w[i] = (c[c[x].l].w[i] + c[c[x].r].w[i]) % 1000000007;
}
inline void Down(int x) {
  for (int i = 1; i >= 0; i--)
    if (c[x].p[i]) {
      Update_sum(c[x].l, c[x].p[i], i);
      Update_sum(c[x].r, c[x].p[i], i);
      c[x].p[i] = 0;
    }
}
inline int Query(int x, int l, int r, int L, int R, int d) {
  if (l >= L && r <= R) return c[x].w[d];
  Down(x);
  int Mid = l + r >> 1;
  if (Mid < L) return Query(c[x].r, Mid + 1, r, L, R, d);
  if (Mid >= R) return Query(c[x].l, l, Mid, L, R, d);
  return (Query(c[x].l, l, Mid, L, R, d) + Query(c[x].r, Mid + 1, r, L, R, d)) %
         1000000007;
}
inline void Build(int& x, int l, int r, int y) {
  x = ++Num;
  if (l == r) {
    int a = s1[g[y][l - 1]], b = s2[g[y][l - 1]];
    c[x].w[0] = a;
    c[x].w[1] = b;
    c[x].w[2] = 1ll * a * (s[y] - l + 1) % 1000000007;
    c[x].w[3] = 1ll * b * l % 1000000007;
    c[x].w[4] = 1;
    return;
  }
  int Mid = l + r >> 1;
  Build(c[x].l, l, Mid, y);
  Build(c[x].r, Mid + 1, r, y);
  Up(x);
}
inline void Update1(int x, int l, int r, int p, int y, int d) {
  if (l == r) {
    if (d == 1) {
      int a = s1[g[y][l - 1]], b = s2[g[y][l - 1]];
      c[x].w[0] = a;
      c[x].w[1] = b;
      if (l < s[y])
        c[x].w[2] =
            1ll * a * (Query(Rt[y], 1, s[y], l + 1, s[y], 4) + 1) % 1000000007;
      else
        c[x].w[3] = a;
      if (l > 1)
        c[x].w[3] =
            1ll * b * (Query(Rt[y], 1, s[y], 1, l - 1, 4) + 1) % 1000000007;
      else
        c[x].w[3] = b;
      c[x].w[4] = 1;
    } else
      memset(c[x].w, 0, sizeof(c[x].w));
    return;
  }
  Down(x);
  int Mid = l + r >> 1;
  if (p <= Mid)
    Update1(c[x].l, l, Mid, p, y, d);
  else
    Update1(c[x].r, Mid + 1, r, p, y, d);
  Up(x);
}
inline void Update(int x, int l, int r, int L, int R, int d, bool t) {
  if (l >= L && r <= R) {
    Update_sum(x, d, t);
    return;
  }
  Down(x);
  int Mid = l + r >> 1;
  if (Mid >= L) Update(c[x].l, l, Mid, L, R, d, t);
  if (Mid < R) Update(c[x].r, Mid + 1, r, L, R, d, t);
  Up(x);
}
inline void Find1(int x, int l, int r, int L, int R) {
  if (S >= 2) return;
  if (l == r) {
    S += c[x].w[4];
    if (S == 2) t = l;
    return;
  }
  Down(x);
  if (l >= L && r <= R) {
    int Mid = l + r >> 1;
    if (S + c[c[x].l].w[4] >= 2)
      Find1(c[x].l, l, Mid, L, R);
    else if (S + c[x].w[4] >= 2)
      S += c[c[x].l].w[4], Find1(c[x].r, Mid + 1, r, L, R);
    else
      S += c[x].w[4];
    return;
  }
  int Mid = l + r >> 1;
  if (Mid >= L) Find1(c[x].l, l, Mid, L, R);
  if (Mid < R) Find1(c[x].r, Mid + 1, r, L, R);
}
inline void Find2(int x, int l, int r, int L, int R) {
  if (S >= 2) return;
  if (l == r) {
    S += c[x].w[4];
    if (S == 2) t = l;
    return;
  }
  Down(x);
  if (l >= L && r <= R) {
    int Mid = l + r >> 1;
    if (S + c[c[x].r].w[4] >= 2)
      Find2(c[x].r, Mid + 1, r, L, R);
    else if (S + c[x].w[4] >= 2)
      S += c[c[x].r].w[4], Find2(c[x].l, l, Mid, L, R);
    else
      S += c[x].w[4];
    return;
  }
  int Mid = l + r >> 1;
  if (Mid < R) Find2(c[x].r, Mid + 1, r, L, R);
  if (Mid >= L) Find2(c[x].l, l, Mid, L, R);
}
inline void Update_seq(int x, int d) {
  if (f[x] > 1 && f[x] < s[a[x]])
    Ans = (Ans + 1ll * d * Query(Rt[a[x]], 1, s[a[x]], 1, f[x] - 1, 0) *
                     Query(Rt[a[x]], 1, s[a[x]], f[x] + 1, s[a[x]], 1) %
                     1000000007) %
          1000000007;
  if (f[x] < s[a[x]]) {
    S = t = 0;
    Find1(Rt[a[x]], 1, s[a[x]], f[x] + 1, s[a[x]]);
    if (t)
      Ans = (Ans +
             1ll * d * s1[x] *
                 (Query(Rt[a[x]], 1, s[a[x]], t, s[a[x]], 3) -
                  1ll * Query(Rt[a[x]], 1, s[a[x]], 1, t - 1, 4) *
                      Query(Rt[a[x]], 1, s[a[x]], t, s[a[x]], 1) % 1000000007) %
                 1000000007) %
            1000000007;
    Update(Rt[a[x]], 1, s[a[x]], f[x] + 1, s[a[x]], d, 1);
  }
  if (f[x] > 1) {
    S = t = 0;
    Find2(Rt[a[x]], 1, s[a[x]], 1, f[x] - 1);
    if (t)
      Ans = (Ans + 1ll * d * s2[x] *
                       (Query(Rt[a[x]], 1, s[a[x]], 1, t, 2) -
                        1ll * Query(Rt[a[x]], 1, s[a[x]], t + 1, s[a[x]], 4) *
                            Query(Rt[a[x]], 1, s[a[x]], 1, t, 0) % 1000000007) %
                       1000000007) %
            1000000007;
    Update(Rt[a[x]], 1, s[a[x]], 1, f[x] - 1, d, 0);
  }
  Update1(Rt[a[x]], 1, s[a[x]], f[x], a[x], d);
}
int main() {
  Read(n);
  for (i = 1; i <= n; i++) Read(d[i].w), d[i].f = i;
  sort(d + 1, d + n + 1, Cmp);
  a[d[1].f] = m = 1;
  for (i = 2; i <= n; i++)
    if (d[i].w == d[i - 1].w)
      a[d[i].f] = m;
    else
      a[d[i].f] = ++m;
  for (i = 1; i <= n; i++) {
    g[a[i]].push_back(i);
    f[i] = g[a[i]].size();
    s1[i] = Query1(a[i]);
    Update1(a[i]);
  }
  memset(b, 0, sizeof(b));
  for (i = n; i; i--) {
    s2[i] = Query1(a[i]);
    Update1(a[i]);
  }
  for (i = 1; i <= m; i++) s[i] = g[i].size(), Build(Rt[i], 1, s[i], i);
  for (i = 1; i <= n; i++)
    if (f[i] > 1 && f[i] < s[a[i]])
      Ans = (Ans + 1ll * Query(Rt[a[i]], 1, s[a[i]], 1, f[i] - 1, 0) *
                       Query(Rt[a[i]], 1, s[a[i]], f[i] + 1, s[a[i]], 1) %
                       1000000007) %
            1000000007;
  Read(Q);
  while (Q--) {
    Read(k);
    Read(x);
    Update_seq(x, k == 1 ? -1 : 1);
    Print((Ans + 1000000007) % 1000000007);
  }
  return 0;
}