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 = -1;
const long long INF = 1e9 + 19;
const int MOD = 1e9 + 7;
void ff(long long& A, long long B) { A = (A + B % MOD + MOD) % MOD; }
struct SegTree {
  vector<long long> data;
  vector<long long> upd;
  vector<int> cntBlock;
  int nn;
  void init(int n) {
    nn = n;
    data.resize(n * 4);
    upd.resize(n * 4);
    cntBlock.resize(n * 4);
  }
  void push(int v, int tl, int tr) {
    if (upd[v] != 0) {
      ff(upd[v * 2 + 1], upd[v]);
      ff(upd[v * 2 + 2], upd[v]);
      ff(data[v * 2 + 1], upd[v] * ((tl + tr) / 2 - tl - cntBlock[v * 2 + 1]));
      ff(data[v * 2 + 2], upd[v] * (tr - (tl + tr) / 2 - cntBlock[v * 2 + 2]));
      upd[v] = 0;
    }
  }
  void add(int l, int r, int val) { add(0, 0, nn, l, r, val); }
  void add(int p, int val) { add(0, 0, nn, p, p + 1, val); }
  void block(int pos, int val) { block(0, 0, nn, pos, val); }
  void block(int v, int tl, int tr, int pos, int val) {
    if (tl + 1 == tr) {
      cntBlock[v] += val;
      assert(data[v] == 0);
      assert(0 <= cntBlock[v] && cntBlock[v] <= (tr - tl));
      return;
    }
    push(v, tl, tr);
    if (pos < (tl + tr) / 2)
      block(v * 2 + 1, tl, (tl + tr) / 2, pos, val);
    else
      block(v * 2 + 2, (tl + tr) / 2, tr, pos, val);
    cntBlock[v] = cntBlock[v * 2 + 1] + cntBlock[v * 2 + 2];
    assert(0 <= cntBlock[v] && cntBlock[v] <= (tr - tl));
  }
  void add(int v, int tl, int tr, int l, int r, long long val) {
    if (r <= tl || tr <= l) return;
    if (l <= tl && tr <= r) {
      ff(data[v], val * ((tr - tl) - cntBlock[v]));
      ff(upd[v], val);
      return;
    }
    push(v, tl, tr);
    add(v * 2 + 1, tl, (tl + tr) / 2, l, r, val);
    add(v * 2 + 2, (tl + tr) / 2, tr, l, r, val);
    data[v] = (data[v * 2 + 1] + data[v * 2 + 2]) % MOD;
  }
  long long getSum(int l, int r) { return getSum(0, 0, nn, l, r); }
  long long getSum(int v, int tl, int tr, int l, int r) {
    if (r <= tl || tr <= l) return 0;
    if (l <= tl && tr <= r) {
      return data[v];
    }
    push(v, tl, tr);
    return (getSum(v * 2 + 1, tl, (tl + tr) / 2, l, r) +
            getSum(v * 2 + 2, (tl + tr) / 2, tr, l, r)) %
           MOD;
  }
};
vector<int> a;
vector<pair<int, int>> query;
void read() {
  int n;
  scanf("%d", &n);
  a.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int m;
  scanf("%d", &m);
  query.resize(m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &query[i].first, &query[i].second);
    query[i].second--;
  }
}
vector<long long> solve() {
  vector<pair<int, int>> tmp;
  vector<int> xx;
  int n = a.size();
  for (int i = 0; i < n; i++) {
    xx.push_back(a[i]);
  }
  sort((xx).begin(), (xx).end());
  xx.resize(unique((xx).begin(), (xx).end()) - xx.begin());
  for (int i = 0; i < n; i++) {
    a[i] = lower_bound((xx).begin(), (xx).end(), a[i]) - xx.begin();
  }
  vector<vector<int>> where(xx.size());
  vector<SegTree> sumL(xx.size());
  vector<SegTree> sumR(xx.size());
  vector<SegTree> cntL(xx.size());
  vector<SegTree> cntR(xx.size());
  vector<vector<int>> valL(xx.size());
  vector<vector<int>> valR(xx.size());
  for (int i = 0; i < n; i++) {
    tmp.push_back({a[i], i});
    where[a[i]].push_back(i);
  }
  sort((tmp).begin(), (tmp).end());
  SegTree help;
  help.init(n);
  long long answer = 0;
  for (int i = 0; i < (int)tmp.size();) {
    int j = i;
    int val = tmp[j].first;
    for (; i < (int)tmp.size() && tmp[j].first == tmp[i].first; i++)
      ;
    for (int t = j; t < i; t++)
      help.add(0, 0, n, tmp[t].second, tmp[t].second + 1, 1);
    int len = i - j;
    sumL[val].init(len);
    sumR[val].init(len);
    cntL[val].init(len);
    cntR[val].init(len);
    valL[val].resize(len);
    valR[val].resize(len);
    for (int t = j; t < i; t++) {
      int zz = help.getSum(0, tmp[t].second);
      valL[val][t - j] = zz;
      cntL[val].add(t - j, zz);
      sumL[val].add(t - j, cntL[val].getSum(0, t - j));
    }
    for (int t = i - 1; t >= j; t--) {
      int zz = help.getSum(tmp[t].second + 1, n);
      cntR[val].add(t - j, zz);
      valR[val][t - j] = zz;
      sumR[val].add(t - j, cntR[val].getSum(t - j + 1, n));
    }
    for (int t = j; t < i; t++) {
      ff(answer, cntL[val].getSum(0, t - j) * cntR[val].getSum(t - j + 1, len));
    }
  }
  vector<long long> res;
  for (auto x : query) {
    int type, pos;
    type = x.first;
    pos = x.second;
    int val = a[pos];
    int t = lower_bound((where[val]).begin(), (where[val]).end(), pos) -
            where[val].begin();
    int len = where[val].size();
    int sign = (type == 1) ? -1 : 1;
    ff(answer, sign * cntL[val].getSum(0, t) * cntR[val].getSum(t + 1, len));
    if (type == 2) {
      sumR[val].block(t, sign * -1);
      sumL[val].block(t, sign * -1);
    }
    sumL[val].add(t, sign * cntL[val].getSum(0, t));
    sumR[val].add(t, sign * cntR[val].getSum(t + 1, len));
    cntL[val].add(t, sign * valL[val][t]);
    cntR[val].add(t, sign * valR[val][t]);
    sumL[val].add(t + 1, len, sign * valL[val][t]);
    sumR[val].add(0, t, sign * valR[val][t]);
    if (type == 1) {
      sumR[val].block(t, sign * -1);
      sumL[val].block(t, sign * -1);
    }
    ff(answer, sign * sumR[val].getSum(t + 1, len) * valL[val][t]);
    ff(answer, sign * sumL[val].getSum(0, t) * valR[val][t]);
    res.push_back(answer);
  }
  return res;
}
void genTest() {
  int n = rand() % 10 + 1;
  int m = rand() % 5 + 1;
  a.clear();
  for (int i = 0; i < n; i++) {
    a.push_back(rand() % 5);
  }
  vector<int> used(n, 0);
  query.clear();
  for (int i = 0; i < m; i++) {
    int pos = rand() % n;
    int type = (used[pos] == 0) ? 1 : 2;
    query.push_back({type, pos});
    used[pos] ^= 1;
  }
}
vector<long long> slow() {
  vector<long long> res;
  int n = a.size();
  vector<int> use(n, 1);
  for (auto x : query) {
    long long answer = 0;
    use[x.second] ^= 1;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
        for (int k = j + 1; k < n; k++)
          for (int l = k + 1; l < n; l++)
            for (int t = l + 1; t < n; t++)
              if (a[j] == a[k] && a[k] == a[l] && a[i] <= a[j] &&
                  a[t] <= a[j] && use[j] && use[k] && use[l])
                answer++;
    res.push_back(answer);
  }
  return res;
}
void printTest() {
  cout << a.size() << endl;
  for (auto x : a) cout << x << " ";
  cout << endl;
  cout << query.size() << endl;
  for (auto x : query) cout << x.first << " " << x.second + 1 << endl;
}
void stress() {
  for (int tt = 0;; tt++) {
    cerr << "tt"
         << " = " << tt << endl;
    genTest();
    printTest();
    auto r1 = solve();
    auto r2 = slow();
    assert(r1 == r2);
  }
}
void printAns(vector<long long> res) {
  for (auto x : res) printf("%lld\n", x);
}
int main() {
  if (1) {
    read();
    printAns(solve());
  } else {
    stress();
  }
  return 0;
}