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 = 1e5 + 5, mod = 1e9 + 7;
inline void add(int &a, int b) {
  if ((a += b) >= mod) a -= mod;
}
inline void mul(int &a, int b) { a = (a * 1ll * b) % mod; }
inline void sub(int &a, int b) {
  if ((a -= b) < 0) a += mod;
}
int arr[N];
int z[N][2];
int bit[N];
void update(int x, int v) {
  for (; x < N; x += x & -x) bit[x] += v;
}
int query(int x) {
  int sum = 0;
  for (; x > 0; x -= x & -x) sum += bit[x];
  return sum;
}
void construct_z(int n, bool pre) {
  memset(bit, 0, sizeof bit);
  for (int i = 0; i < n; i++) {
    z[i][pre] = query(arr[i] + 1);
    update(arr[i] + 1, 1);
  }
}
vector<int> cnt[N][2];
vector<int> ans[N][2];
vector<int> Ac[N][2];
vector<int> on[N][2];
vector<int> zs[N][2];
int rev[N][2];
int fr[N];
int n;
int sq[N];
void construct(bool flag) {
  for (int i = 0; i < n; i++) {
    int x = arr[i];
    if (zs[x][flag].size() % sq[x] == 0) {
      cnt[x][flag].push_back(0);
      ans[x][flag].push_back(0);
      Ac[x][flag].push_back(0);
    }
    add(Ac[x][flag].back(), z[i][flag]);
    add(Ac[x][flag].back(), ans[x][flag].back());
    add(ans[x][flag].back(), z[i][flag]);
    rev[i][flag] = on[x][flag].size();
    cnt[x][flag].back()++;
    on[x][flag].push_back(1);
    zs[x][flag].push_back(z[i][flag]);
  }
}
int get(int indx, bool flag, bool mid) {
  if (indx <= -1 || indx >= n) return 0;
  int x = arr[indx];
  int W = indx;
  if (flag) indx = n - indx - 1;
  int len = sq[x];
  int ret = 0;
  indx = rev[indx][flag];
  int ac = 0;
  for (int i = 0; i <= indx;) {
    if (i % len == 0 && i + len - 1 <= indx) {
      if (!mid) {
        int temp = cnt[x][flag][i / len];
        int w = ac;
        mul(w, temp);
        add(ret, w);
        add(ret, Ac[x][flag][i / len]);
      } else
        add(ret, ans[x][flag][i / len]);
      add(ac, ans[x][flag][i / len]);
      i += len;
    } else {
      if (on[x][flag][i]) {
        add(ret, zs[x][flag][i]);
        if (!mid) add(ret, ac);
        add(ac, zs[x][flag][i]);
      }
      ++i;
    }
  }
  return ret;
}
void update(int indx, bool flag, bool ad) {
  if (indx <= -1 || indx >= n) return;
  int x = arr[indx];
  int len = sq[x];
  if (flag) indx = n - indx - 1;
  int i = rev[indx][flag] / len * len;
  on[x][flag][rev[indx][flag]] ^= true;
  if (ad)
    zs[x][flag][rev[indx][flag]] = z[indx][flag];
  else
    zs[x][flag][rev[indx][flag]] = 0;
  int j = i + len - 1;
  cnt[x][flag][i / len] = 0;
  ans[x][flag][i / len] = 0;
  Ac[x][flag][i / len] = 0;
  int ac = 0;
  while (i <= j && i < on[x][flag].size()) {
    if (on[x][flag][i]) {
      cnt[x][flag][i / len] += on[x][flag][i];
      add(ans[x][flag][i / len], zs[x][flag][i]);
      add(Ac[x][flag][i / len], zs[x][flag][i]);
      add(Ac[x][flag][i / len], ac);
      add(ac, zs[x][flag][i]);
    }
    i++;
  }
}
vector<int> init[N][2];
int last[N];
set<int> st[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]] = 1;
  }
  int id = 0;
  for (auto &x : mp) x.second = id++;
  for (int i = 0; i < id; i++)
    st[i].insert(n), st[i].insert(n + 1), st[i].insert(-1), st[i].insert(-2);
  for (int i = 0; i < n; i++) arr[i] = mp[arr[i]], fr[arr[i]]++;
  for (int i = 0; i < n; i++) {
    sq[arr[i]] = (int)sqrt((double)fr[arr[i]] + .5) + 1;
  }
  for (int i = 0; i < n; i++) {
    st[arr[i]].insert(i);
  }
  construct_z(n, 0);
  construct(0);
  reverse(arr, arr + n);
  construct_z(n, 1);
  construct(1);
  reverse(arr, arr + n);
  for (int i = 0; i < n; i++) {
    int last = 0;
    if (init[arr[i]][0].size()) last = init[arr[i]][0].back();
    add(last, z[i][0]);
    init[arr[i]][0].push_back(last);
  }
  reverse(arr, arr + n);
  for (int i = 0; i < n; i++) {
    int last = 0;
    if (init[arr[i]][1].size()) last = init[arr[i]][1].back();
    add(last, z[i][1]);
    init[arr[i]][1].push_back(last);
  }
  reverse(arr, arr + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (init[i][0].size() < 3) continue;
    for (int j = 1; j + 1 < init[i][0].size(); j++) {
      int indx = (int)init[i][0].size() - j - 2;
      int x = init[i][0][j - 1];
      mul(x, init[i][1][indx]);
      add(ans, x);
    }
  }
  int m;
  cin >> m;
  while (m--) {
    int t, x;
    cin >> t >> x;
    x--;
    if (t == 1) {
      auto it = st[arr[x]].lower_bound(x);
      auto T = it;
      T++;
      int temp = get(*T, 1, 1);
      T--;
      T--;
      int temp2 = get(*T, 0, 1);
      mul(temp, temp2);
      sub(ans, temp);
      T = it;
      ++T;
      ++T;
      temp = get(*T, 1, 0);
      mul(temp, z[x][0]);
      sub(ans, temp);
      T = it;
      --T;
      --T;
      temp = get(*T, 0, 0);
      mul(temp, z[n - x - 1][1]);
      sub(ans, temp);
      st[arr[x]].erase(x);
      update(x, 0, 0);
      update(x, 1, 0);
    } else {
      st[arr[x]].insert(x);
      auto it = st[arr[x]].lower_bound(x);
      auto T = it;
      T++;
      int temp = get(*T, 1, 1);
      T--;
      T--;
      int temp2 = get(*T, 0, 1);
      mul(temp, temp2);
      add(ans, temp);
      T = it;
      ++T;
      ++T;
      temp = get(*T, 1, 0);
      mul(temp, z[x][0]);
      add(ans, temp);
      T = it;
      --T;
      --T;
      temp = get(*T, 0, 0);
      mul(temp, z[n - x - 1][1]);
      add(ans, temp);
      update(x, 0, 1);
      update(x, 1, 1);
    }
    cout << ans << '\n';
  }
  return 0;
}