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;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long a, long long b, long long m) {
  if (b == 0LL) return 1LL;
  if (b == 1LL) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1LL) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
const int M = 1e9 + 7;
const int N = 100100;
int a[N];
int pre[N], suf[N];
int BIT[N];
int sum(int x) {
  int r = 0;
  while (x > 0) {
    r += BIT[x];
    x -= (x & -x);
  }
  return r;
}
void update(int x, int v) {
  while (x < N) {
    BIT[x] += v;
    x += (x & -x);
  }
}
inline int sum(int a, int b) {
  int c = (a + b);
  if (c >= M) c -= M;
  return c;
}
inline int prod(int a, int b) { return (a * 1LL * b) % M; }
vector<int> vec[N];
int SZ = 4;
struct node {
  vector<int> x;
  node operator+(const node& rhs) const {
    node r;
    r.x = vector<int>(16, 0);
    for (int i = 0; i < (4); ++i) {
      for (int j = 0; j < (4); ++j) {
        for (int k = 0; k < (4); ++k) {
          r.x[4 * i + j] =
              sum(r.x[4 * i + j], prod(x[4 * i + k], rhs.x[4 * k + j]));
        }
      }
    }
    return r;
  }
};
template <class T>
struct ST {
  vector<T> st;
  int n;
  T ini;
  ST() {}
  ST(int n, T ini) : st(2 * n, ini), n(n), ini(ini) {}
  void upd(int pos, T val) {
    for (st[pos += n] = val; pos /= 2;) st[pos] = st[2 * pos] + st[2 * pos + 1];
  }
  T query(int x, int y) {
    T ra = ini, rb = ini;
    for (x += n, y += n + 1; x < y; x /= 2, y /= 2) {
      if (x & 1) ra = ra + st[x], x++;
      if (y & 1) --y, rb = st[y] + rb;
    }
    return ra + rb;
  }
};
vector<int> def(16, 0);
node make(int id, int good) {
  vector<int> mat = def;
  if (!good) return {mat};
  mat[0 * 4 + 1] = pre[id];
  mat[1 * 4 + 2] = 1;
  mat[2 * 4 + 3] = suf[id];
  return {mat};
}
int good[N];
int pos[N];
ST<node> T[N];
int cur[N];
int32_t main() {
  def[0] = def[5] = def[10] = def[15] = 1;
  int n;
  scanf("%d", &n);
  vector<int> comp;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    good[i] = 1;
    comp.push_back(a[i]);
  }
  sort(comp.begin(), comp.end());
  comp.erase(unique(comp.begin(), comp.end()), comp.end());
  for (int i = 1; i <= n; i++) {
    a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin() + 1;
  }
  for (int i = 1; i <= n; i++) {
    pre[i] = sum(a[i]);
    update(a[i], 1);
    vec[a[i]].push_back(i);
  }
  for (int j = 0; j < N; j++) BIT[j] = 0;
  for (int i = n; i >= 1; i--) {
    suf[i] = sum(a[i]);
    update(a[i], 1);
  }
  node ini = {def};
  long long ans = 0;
  for (int i = 1; i <= (int)comp.size(); i++) {
    int tam = (int)vec[i].size();
    T[i] = ST<node>(tam, ini);
    int p = 0;
    for (int x : vec[i]) {
      T[i].upd(p, make(x, good[x]));
      pos[x] = p++;
    }
    cur[i] = T[i].query(0, p - 1).x[3];
    ans = (ans + cur[i]);
    if (ans >= M) ans -= M;
  }
  int m;
  scanf("%d", &m);
  while (m--) {
    int t, v;
    scanf("%d%d", &t, &v);
    good[v] ^= 1;
    ans = (ans - cur[a[v]]);
    if (ans < 0) ans += M;
    T[a[v]].upd(pos[v], make(v, good[v]));
    cur[a[v]] = T[a[v]].query(0, (int)vec[a[v]].size() - 1).x[3];
    ans = (ans + cur[a[v]]);
    if (ans >= M) ans -= M;
    if (ans < 0) ans += M;
    printf("%lld\n", ans);
  }
}