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 maxn = 1e5 + 79;
const long long mod = 1e9 + 7;
vector<int> bit(maxn, 0), smallpf(maxn, 0), smallsf(maxn, 0);
void add(int pos) {
  for (; pos < maxn; pos = (pos | (pos + 1))) bit[pos]++;
}
int sum(int pos) {
  int rval = 0;
  for (; pos >= 0; pos = (pos & (pos + 1)) - 1) rval += bit[pos];
  return rval;
}
void addm(int& a, const int& b) {
  a += b;
  while (a >= mod) a -= mod;
  while (a < 0) a += mod;
}
class segment_tree_point_update {
  int n;
  vector<int> id;

 public:
  vector<array<array<int, 4>, 4> > st;
  void merge(int v) {
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++) st[v][i][j] = 0;
    for (int i = 0; i < 4; i++)
      for (int j = i; j < 4; j++)
        for (int k = j; k < 4; k++)
          addm(st[v][i][k],
               (st[v * 2 + 1][i][j] * 1ll * st[v * 2 + 2][j][k]) % mod);
  }
  void update(int i) {
    st[i + (n - 1)][0][1] ^= smallpf[id[i]];
    st[i + (n - 1)][1][2] ^= 1;
    st[i + (n - 1)][2][3] ^= smallsf[id[i]];
    for (i += n - 1; i > 0; i = (i - 1) / 2) merge((i - 1) / 2);
  }
  void build(vector<int>& i) {
    n = 1;
    id = i;
    while (n < i.size()) n <<= 1;
    st.resize(n * 2);
    for (int i = 0; i < n * 2; i++) {
      for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++) st[i][j][k] = 0;
      for (int j = 0; j < 4; j++) st[i][j][j] = 1;
    }
    for (int j = 0; j < id.size(); j++) update(j);
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, cnt = 1;
  cin >> n;
  vector<int> a(n), myid(n);
  set<int> cs;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cs.insert(a[i]);
  }
  while (!cs.empty()) {
    m[*cs.begin()] = cnt++;
    cs.erase(cs.begin());
  }
  vector<vector<int> > id(cnt);
  vector<segment_tree_point_update> st(cnt);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    a[i] = m[a[i]];
    smallpf[i] = sum(a[i]);
    myid[i] = id[a[i]].size();
    id[a[i]].push_back(i);
    add(a[i]);
  }
  bit.assign(maxn, 0);
  for (int i = n - 1; i >= 0; i--) {
    smallsf[i] = sum(a[i]);
    add(a[i]);
  }
  for (int i = 1; i < cnt; i++) {
    st[i].build(id[i]);
    addm(ans, st[i].st[0][0][3]);
  }
  int q;
  cin >> q;
  while (q--) {
    int t, x;
    cin >> t >> x;
    x--;
    addm(ans, -st[a[x]].st[0][0][3]);
    st[a[x]].update(myid[x]);
    addm(ans, st[a[x]].st[0][0][3]);
    cout << ans << "\n";
  }
  return 0;
}