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;
int read() {
  char ch = getchar();
  int x = 0, fl = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch - '0');
  return x * fl;
}
const int N = 100005;
const long long mod = 1e9 + 7;
int n, m, ct[N], a[N], b[N], len;
bool can[N];
void upd(long long &x, long long y) { x = (x + y) % mod; }
namespace bf {
struct bit {
  long long t[N];
  void clear() {
    for (int i = 1; i <= len; i++) t[i] = 0LL;
  }
  void mdf(int x, long long y) {
    for (int i = x; i <= len; i += (i & -i)) upd(t[i], y);
  }
  long long qry(int x) {
    long long res = 0LL;
    for (int i = x; i; i -= (i & -i)) upd(res, t[i]);
    return res;
  }
} st[6];
long long f[N][6], p[N][6];
long long getans() {
  long long ans = 0LL;
  for (int i = 1; i <= 5; i++) {
    st[i].clear();
    for (int j = 1; j <= len; j++) p[j][i] = 0LL;
  }
  for (int i = 1; i <= n; i++) {
    f[i][1] = 1LL;
    if (can[i]) {
      f[i][2] = st[1].qry(a[i]);
      f[i][3] = p[a[i]][2];
      f[i][4] = p[a[i]][3];
    } else {
      f[i][2] = f[i][3] = f[i][4] = 0LL;
    }
    f[i][5] = (st[4].qry(len) - st[4].qry(a[i] - 1) + mod) % mod;
    st[1].mdf(a[i], f[i][1]);
    upd(p[a[i]][2], f[i][2]);
    upd(p[a[i]][3], f[i][3]);
    st[4].mdf(a[i], f[i][4]);
    upd(ans, f[i][5]);
  }
  return ans;
}
void work() {
  while (m--) {
    int opt = read(), id = read();
    if (opt == 1)
      can[id] = 0;
    else
      can[id] = 1;
    cout << getans() << '\n';
  }
}
}  // namespace bf
namespace subtask1 {
int ll[N], rr[N], rt[N];
struct bit {
  int t[N];
  void clear() { memset(t, 0, sizeof(t)); }
  void mdf(int x) {
    for (int i = x; i <= len; i += (i & -i)) t[i]++;
  }
  int qry(int x) {
    int res = 0;
    for (int i = x; i; i -= (i & -i)) res += t[i];
    return res;
  }
} st;
struct node {
  int f[3][3];
} t[N << 5];
int ls[N << 5], rs[N << 5], tot;
void upd_(int &x, long long y) { x = (1LL * x + 1LL * y) % mod; }
void psu(int rt) {
  int _l = ls[rt], _r = rs[rt];
  for (int i = 0; i < 3; i++) {
    for (int j = i; j < 3; j++) {
      t[rt].f[i][j] = (t[_l].f[i][j] + t[_r].f[i][j]) % mod;
      for (int k = i; k < j; k++) {
        upd_(t[rt].f[i][j], 1LL * t[_l].f[i][k] * t[_r].f[k + 1][j] % mod);
      }
    }
  }
}
void chg(int rt, int l, int r, int pv, int w) {
  if (l == r) {
    t[rt].f[0][0] = 1LL * w * ll[pv];
    t[rt].f[1][1] = 1LL * w;
    t[rt].f[2][2] = 1LL * w * rr[pv];
    return;
  }
  int mid = (l + r) >> 1;
  if (pv <= mid) {
    if (!ls[rt]) ls[rt] = ++tot;
    chg(ls[rt], l, mid, pv, w);
  } else {
    if (!rs[rt]) rs[rt] = ++tot;
    chg(rs[rt], mid + 1, r, pv, w);
  }
  psu(rt);
}
void work() {
  st.clear();
  for (int i = 1; i <= n; i++) {
    ll[i] = st.qry(a[i]);
    st.mdf(a[i]);
  }
  st.clear();
  for (int i = n; i; i--) {
    rr[i] = st.qry(a[i]);
    st.mdf(a[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (!rt[a[i]]) rt[a[i]] = ++tot;
    chg(rt[a[i]], 1, n, i, 1);
  }
  long long ans = 0LL;
  for (int i = 1; i <= len; i++) upd(ans, t[rt[i]].f[0][2]);
  while (m--) {
    int opt = read(), id = read();
    int v = a[id];
    upd(ans, mod - t[rt[v]].f[0][2]);
    if (opt == 1)
      chg(rt[v], 1, n, id, 0);
    else
      chg(rt[v], 1, n, id, 1);
    upd(ans, t[rt[v]].f[0][2]);
    cout << ans << '\n';
  }
}
}  // namespace subtask1
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = b[i] = read();
  sort(b + 1, b + n + 1);
  len = unique(b + 1, b + n + 1) - b - 1;
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(b + 1, b + len + 1, a[i]) - b;
    can[i] = 1;
  }
  m = read();
  if (1LL * n * m <= 1e6)
    bf::work();
  else
    subtask1::work();
  return 0;
}