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>
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
using namespace ::std;
const long long maxn = 1e5 + 500;
const long long mod = 1e9 + 7;
struct M {
  long long a[5][5];
};
long long ent(long long n, long long k) {
  if (n < 0) return 0;
  if (k == 0) return 1;
  if (k == 1) return n;
  if (k == 2) return (n * (n - 1) / 2) % mod;
  if (k == 3) return ((n * (n - 1) * (n - 2)) / 6) % mod;
  return 0;
}
M merge(M a, M b) {
  M ans;
  for (long long i = 0; i < 5; i++) {
    for (long long j = i; j < 5; j++) {
      ans.a[i][j] = (b.a[i][j] + a.a[i][j]) % mod;
      for (long long k = i; k < j; k++)
        ans.a[i][j] = (ans.a[i][j] + (a.a[i][k] * b.a[k + 1][j])) % mod;
    }
  }
  return ans;
}
M chenge(long long x, long long t) {
  M ans;
  for (long long i = 0; i < 5; i++) {
    for (long long j = 0; j < 5; j++) {
      if (i == j) {
        ans.a[i][j] = t;
      } else if (i < j) {
        ans.a[i][j] = 0;
      }
    }
  }
  ans.a[4][4] = x + 1;
  ans.a[0][0] = 1 + x;
  ans.a[0][1] = x * t;
  return ans;
}
vector<M> seg[maxn];
vector<long long> vec[maxn];
long long sum;
void pri(M a) {
  for (long long i = 0; i < 5; i++) {
    for (long long j = 0; j < i; j++) cout << 0 << ' ';
    for (long long j = i; j < 5; j++) {
      cout << a.a[i][j] << ' ';
    }
    cout << endl;
  }
}
void bild(long long b, long long l = 0, long long r = 0, long long node = 0) {
  if (node == 0) {
    l = 0;
    r = vec[b].size();
    node = 1;
    seg[b].resize(vec[b].size() * 4);
  }
  if (l + 1 == r) {
    if (r == vec[b].size()) {
      seg[b][node] = chenge(vec[b][l], 0);
      seg[b][node].a[0][0]--;
      seg[b][node].a[4][4]--;
    } else {
      seg[b][node] = chenge(vec[b][l], 1);
    }
    return;
  }
  long long mid = (l + r) / 2;
  bild(b, l, mid, 2 * node);
  bild(b, mid, r, 2 * node + 1);
  seg[b][node] = merge(seg[b][2 * node], seg[b][2 * node + 1]);
  if (node == 1) sum += seg[b][node].a[0][4];
}
void update(long long b, long long x, long long t, long long l = 0,
            long long r = 0, long long node = 0) {
  if (node == 0) {
    l = 0;
    r = vec[b].size();
    node = 1;
    sum -= seg[b][node].a[0][4];
  }
  if (l + 1 == r) {
    seg[b][node] = chenge(vec[b][l], t);
    return;
  }
  long long mid = (l + r) / 2;
  if (x < mid) {
    update(b, x, t, l, mid, 2 * node);
  } else {
    update(b, x, t, mid, r, 2 * node + 1);
  }
  seg[b][node] = merge(seg[b][2 * node], seg[b][2 * node + 1]);
  if (node == 1) {
    sum += seg[b][node].a[0][4];
  }
}
long long a[maxn];
long long k[maxn];
long long fen[maxn];
long long last[maxn];
long long chand[maxn];
void updateFen(long long x, long long v) {
  for (x++; x < maxn; x += (x & (-x))) fen[x] += v;
}
long long sumFen(long long x) {
  long long ans = 0;
  for (x++; x; x -= (x & (-x))) ans += fen[x];
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> comp;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    comp.push_back(a[i]);
  }
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      for (long long k = j + 1; k < n; k++) {
        for (long long u = k + 1; u < n; u++) {
          for (long long t = u + 1; t < n; t++) {
            res +=
                (a[j] == a[k] && a[k] == a[u] && a[t] <= a[u] && a[i] <= a[j]);
          }
        }
      }
    }
  }
  sort(comp.begin(), comp.end());
  comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
  for (long long i = 0; i < n; i++) {
    a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin();
  }
  fill(last, last + maxn, -1);
  for (long long i = 0; i < n; i++) {
    long long v = a[i];
    updateFen(v, 1);
    k[i] = sumFen(v - 1);
    if (last[v] == -1) {
      vec[v].push_back(k[i]);
      chand[i] = 1;
    } else {
      chand[i] = chand[last[v]] + 1;
      vec[v].push_back(k[i] - k[last[v]]);
    }
    last[a[i]] = i;
  }
  for (long long i = 0; i < comp.size(); i++) {
    vec[i].push_back(sumFen(i - 1) - k[last[i]]);
    bild(i);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long t, x;
    cin >> t >> x;
    t--;
    x--;
    update(a[x], chand[x] - 1, t);
    cout << sum % mod << endl;
  }
}