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;
long long a, d[100002], g, h, j, k, l, n, m, pas, mod = 1000000007, y, t;
long long i, s;
map<long long, long long> q;
set<long long> w;
vector<vector<pair<long long, long long> > > v, v1;
struct tre {
  int val;
  tre *L;
  tre *R;
  tre() {
    val = 0;
    L = NULL;
    R = NULL;
  }
};
tre *root, *root1;
void add(tre *&it, long long l, long long r, long long idx) {
  if (l >= idx || r < idx) return;
  if (!it) it = new tre();
  it->val++;
  if (l + 1 == r) return;
  add(it->L, l, (l + r) / 2, idx);
  add(it->R, (l + r) / 2, r, idx);
}
long long fnd(tre *&it, long long l, long long r, long long idx) {
  if (!it) return 0;
  if (l > idx) return 0;
  if (r <= idx) return it->val;
  return fnd(it->L, l, (l + r) / 2, idx) + fnd(it->R, (l + r) / 2, r, idx);
}
struct tr {
  int ra;
  int la;
  long long Qra;
  int Qrd;
  long long Qla;
  long long Qshr;
  long long Qshl;
  tr *L;
  tr *R;
  tr() {
    ra = 0;
    la = 0;
    Qra = 0;
    Qrd = 0;
    Qla = 0;
    Qshr = 0;
    Qshl = 0;
    L = NULL;
    R = NULL;
  }
};
tr *rt[100002];
long long flag, rao;
void ad(tr *&it, long long l, long long r, long long idx, long long val) {
  if (l > idx || r <= idx) return;
  if (!it) it = new tr();
  if (flag) {
    it->ra += val;
  } else {
    it->la += val;
  }
  if (l + 1 == r) return;
  ad(it->L, l, (l + r) / 2, idx, val);
  ad(it->R, (l + r) / 2, r, idx, val);
}
void aD(tr *&it, long long l, long long r, long long idx, long long val) {
  if (l > idx || r <= idx) return;
  if (!it) it = new tr();
  if (flag) {
    it->ra += val;
  } else {
    it->la += val;
  }
  if (l + 1 == r) return;
  ad(it->L, l, (l + r) / 2, idx, val);
  ad(it->R, (l + r) / 2, r, idx, val);
}
long long sum(tr *&it, long long l, long long r, long long lf, long long rg) {
  if (!it) return 0;
  if (l >= rg || r <= lf) return 0;
  if (l >= lf && r <= rg) {
    return (lf ? it->ra : it->la);
  }
  return sum(it->L, l, (l + r) / 2, lf, rg) +
         sum(it->R, (l + r) / 2, r, lf, rg);
}
void shd(tr *&it) {
  if (it->L) {
    it->L->Qla += it->Qshl * (it->L->Qrd / 2);
    it->L->Qra += it->Qshr * (it->L->Qrd / 2);
    it->L->Qshl += it->Qshl;
    it->L->Qshr += it->Qshr;
  }
  if (it->R) {
    it->R->Qla += it->Qshl * (it->R->Qrd / 2);
    it->R->Qra += it->Qshr * (it->R->Qrd / 2);
    it->R->Qshl += it->Qshl;
    it->R->Qshr += it->Qshr;
  }
  it->Qshl = 0;
  it->Qshr = 0;
  return;
}
void ad1(tr *&it, long long l, long long r, long long lf, long long rg,
         long long val) {
  if (!it) {
    if (rao)
      it = new tr();
    else
      return;
  }
  if (l >= rg || r <= lf) return;
  if ((it->Qshl | it->Qshr)) shd(it);
  if (l >= lf && r <= rg) {
    if (flag) {
      if (rao)
        it->Qra += val;
      else {
        it->Qra += val * (it->Qrd / 2);
        it->Qshr += val;
      }
    } else {
      if (rao)
        it->Qla += val;
      else {
        it->Qla += val * (it->Qrd / 2);
        it->Qshl += val;
      }
    }
    it->Qrd += rao;
    return;
  }
  ad1(it->L, l, (l + r) / 2, lf, rg, val);
  ad1(it->R, (l + r) / 2, r, lf, rg, val);
  it->Qla = it->L->Qla + it->R->Qla;
  it->Qrd = it->L->Qrd + it->R->Qrd;
  it->Qra = it->L->Qra + it->R->Qra;
}
long long sum1(tr *&it, long long l, long long r, long long lf, long long rg) {
  if (!it) return 0;
  if (l >= rg || r <= lf) return 0;
  if (l >= lf && r <= rg) {
    return (lf ? it->Qra : it->Qla);
  }
  if ((it->Qshl | it->Qshr)) shd(it);
  return sum1(it->L, l, (l + r) / 2, lf, rg) +
         sum1(it->R, (l + r) / 2, r, lf, rg);
}
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    d[i] = a;
    w.insert(a);
  }
  v.push_back({});
  v1.push_back({});
  for (set<long long>::iterator it = w.begin(); it != w.end(); it++) {
    q[*it] = ++l;
    v.push_back({});
    v1.push_back({});
  }
  flag = 0;
  for (i = 0; i < n; i++) {
    d[i] = q[d[i]];
    k = fnd(root, 0, n, d[i]);
    v[d[i]].push_back({i, k});
    add(root, 0, n, d[i]);
    ad(rt[d[i]], 0, n, i, k);
  }
  flag = 1;
  rao = 1;
  for (i = n - 1; i >= 0; i--) {
    k = fnd(root1, 0, n, d[i]);
    v1[d[i]].push_back({-i, k});
    add(root1, 0, n, d[i]);
    ad(rt[d[i]], 0, n, i, k);
    long long le = sum(rt[d[i]], 0, n, 0, i);
    long long ri = sum(rt[d[i]], 0, n, i + 1, n);
    flag = 0;
    ad1(rt[d[i]], 0, n, i, i + 1, le);
    flag = 1;
    ad1(rt[d[i]], 0, n, i, i + 1, ri);
    pas = (pas + 1ll * le * ri) % mod;
  }
  rao = 0;
  if (h) return 0;
  cin >> m;
  for (i = 0; i < m; i++) {
    rao = 0;
    scanf("%d%d", &a, &s);
    s--;
    if (a == 2) {
      l = d[s];
      k = lower_bound(v[l].begin(), v[l].end(), make_pair(s, 0ll))->second;
      j = lower_bound(v1[l].begin(), v1[l].end(), make_pair(-s, 0ll))->second;
      long long p1 = sum(rt[l], 0, n, s + 1, n);
      long long p2 = sum(rt[l], 0, n, 0, s);
      pas = (pas + 1ll * p1 * p2) % mod;
      pas = (pas + 1ll * sum1(rt[l], 0, n, s + 1, n) * k) % mod;
      pas = (pas + 1ll * j * sum1(rt[l], 0, n, 0, s)) % mod;
      flag = 0;
      ad1(rt[l], 0, n, s + 1, n, k);
      rao = 1;
      ad1(rt[l], 0, n, s, s + 1, p2);
      rao = 0;
      flag = 1;
      ad1(rt[l], 0, n, 0, s, j);
      rao = 1;
      ad1(rt[l], 0, n, s, s + 1, p1);
      rao = 0;
      flag = 0;
      ad(rt[l], 0, n, s, k);
      flag = 1;
      ad(rt[l], 0, n, s, j);
    } else {
      l = d[s];
      k = lower_bound(v[l].begin(), v[l].end(), make_pair(s, 0ll))->second;
      j = lower_bound(v1[l].begin(), v1[l].end(), make_pair(-s, 0ll))->second;
      long long p1 = sum(rt[l], 0, n, s + 1, n);
      long long p2 = sum(rt[l], 0, n, 0, s);
      pas = (pas - 1ll * p1 * p2 % mod + mod) % mod;
      pas = (pas - 1ll * sum1(rt[l], 0, n, s + 1, n) * k % mod + mod) % mod;
      pas = (pas - 1ll * j * sum1(rt[l], 0, n, 0, s) % mod + mod) % mod;
      flag = 0;
      ad1(rt[l], 0, n, s + 1, n, -k);
      rao = -1;
      ad1(rt[l], 0, n, s, s + 1, -p2);
      rao = 0;
      flag = 1;
      ad1(rt[l], 0, n, 0, s, -j);
      rao = -1;
      ad1(rt[l], 0, n, s, s + 1, -p1);
      rao = 0;
      flag = 0;
      ad(rt[l], 0, n, s, -k);
      flag = 1;
      ad(rt[l], 0, n, s, -j);
    }
    cout << pas << endl;
  }
}