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;
using ll = long long;
using uint = unsigned int;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
template <class T, class U>
void chmax(T& x, U y) {
  if (x < y) x = y;
}
template <class T, class U>
void chmin(T& x, U y) {
  if (y < x) x = y;
}
template <class T>
void mkuni(V<T>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
template <class T>
int lwb(const V<T>& v, const T& x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <unsigned int mod_>
struct ModInt {
  using uint = unsigned int;
  using ll = long long;
  using ull = unsigned long long;
  constexpr static uint mod = mod_;
  uint v;
  ModInt() : v(0) {}
  ModInt(ll _v) : v(normS(_v % mod + mod)) {}
  explicit operator bool() const { return v != 0; }
  static uint normS(const uint& x) { return (x < mod) ? x : x - mod; }
  static ModInt make(const uint& x) {
    ModInt m;
    m.v = x;
    return m;
  }
  ModInt operator+(const ModInt& b) const { return make(normS(v + b.v)); }
  ModInt operator-(const ModInt& b) const { return make(normS(v + mod - b.v)); }
  ModInt operator-() const { return make(normS(mod - v)); }
  ModInt operator*(const ModInt& b) const { return make((ull)v * b.v % mod); }
  ModInt operator/(const ModInt& b) const { return *this * b.inv(); }
  ModInt& operator+=(const ModInt& b) { return *this = *this + b; }
  ModInt& operator-=(const ModInt& b) { return *this = *this - b; }
  ModInt& operator*=(const ModInt& b) { return *this = *this * b; }
  ModInt& operator/=(const ModInt& b) { return *this = *this / b; }
  ModInt& operator++(int) { return *this = *this + 1; }
  ModInt& operator--(int) { return *this = *this - 1; }
  ll extgcd(ll a, ll b, ll& x, ll& y) const {
    ll p[] = {a, 1, 0}, q[] = {b, 0, 1};
    while (*q) {
      ll t = *p / *q;
      for (int i = 0; i < int(3); i++) swap(p[i] -= t * q[i], q[i]);
    }
    if (p[0] < 0)
      for (int i = 0; i < int(3); i++) p[i] = -p[i];
    x = p[1], y = p[2];
    return p[0];
  }
  ModInt inv() const {
    ll x, y;
    extgcd(v, mod, x, y);
    return make(normS(x + mod));
  }
  ModInt pow(ll p) const {
    if (p < 0) return inv().pow(-p);
    ModInt a = 1;
    ModInt x = *this;
    while (p) {
      if (p & 1) a *= x;
      x *= x;
      p >>= 1;
    }
    return a;
  }
  bool operator==(const ModInt& b) const { return v == b.v; }
  bool operator!=(const ModInt& b) const { return v != b.v; }
  friend istream& operator>>(istream& o, ModInt& x) {
    ll tmp;
    o >> tmp;
    x = ModInt(tmp);
    return o;
  }
  friend ostream& operator<<(ostream& o, const ModInt& x) { return o << x.v; }
};
using mint = ModInt<1000000007>;
template <class D>
struct segtree {
  int N;
  vector<D> val;
  segtree() {}
  segtree(int n) {
    N = 1;
    while (N < n) N *= 2;
    val.assign(N * 2, D());
  }
  segtree(const vector<D>& ds) {
    int n = ds.size();
    N = 1;
    while (N < n) N *= 2;
    val.assign(N * 2, D());
    for (int i = 0; i < int(n); i++) val[i + N] = ds[i];
    for (int i = N - 1; i > 0; i--) val[i] = D::op(val[i * 2], val[i * 2 + 1]);
  }
  void assign(int k, D d) {
    k += N;
    val[k] = d;
    k /= 2;
    while (k) {
      val[k] = D::op(val[k * 2], val[k * 2 + 1]);
      k /= 2;
    }
  }
  D query(int a, int b) {
    D L = D(), R = D();
    a += N, b += N;
    while (a < b) {
      if (a & 1) L = D::op(L, val[a++]);
      if (b & 1) R = D::op(val[--b], R);
      a /= 2, b /= 2;
    }
    return D::op(L, R);
  }
};
struct D {
  mint l, lo, lor, o, OR, r;
  D() {}
  D(int l_, int r_) : l(l_), o(1), r(r_) {}
  static D op(const D& x, const D& y) {
    D z;
    z.l = x.l + y.l;
    z.lo = x.lo + x.l * y.o + y.lo;
    z.lor = x.lor + x.lo * y.r + x.l * y.OR + y.lor;
    z.o = x.o + y.o;
    z.OR = x.OR + x.o * y.r + y.OR;
    z.r = x.r + y.r;
    return z;
  }
  friend ostream& operator<<(ostream& o, const D& d) { return o << d.l; }
};
struct BIT {
  using D = int;
  int N;
  vector<D> bit;
  BIT(int n) {
    N = n;
    bit.assign(n + 1, 0);
  }
  BIT() {}
  void init(int n) {
    N = n;
    bit.assign(n + 1, 0);
  }
  D sum(int i) {
    D s = 0;
    while (i > 0) {
      s += bit[i];
      i -= (i & -i);
    }
    return s;
  }
  D val(int i) { return sum(i + 1) - sum(i); }
  void add(int i, D x) {
    i++;
    while (i <= N) {
      bit[i] += x;
      i += (i & -i);
    }
  }
  void assign(int i, D x) { add(i, x - val(i)); }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int N;
  cin >> N;
  V<int> A(N);
  for (int i = 0; i < int(N); i++) cin >> A[i];
  V<int> vs = A;
  mkuni(vs);
  for (int i = 0; i < int(N); i++) A[i] = lwb(vs, A[i]);
  int K = int(vs.size());
  V<int> cnt(K);
  V<int> idx(N);
  for (int i = 0; i < int(N); i++) {
    idx[i] = cnt[A[i]]++;
  }
  V<int> L(N), R(N);
  {
    BIT bit(K);
    for (int i = 0; i < int(N); i++) {
      L[i] = bit.sum(A[i] + 1);
      bit.add(A[i], 1);
    }
    bit = BIT(K);
    for (int i = int(N) - 1; i >= 0; i--) {
      R[i] = bit.sum(A[i] + 1);
      bit.add(A[i], 1);
    }
  }
  void(0);
  void(0);
  V<segtree<D>> ss(K);
  for (int i = 0; i < int(K); i++) ss[i] = segtree<D>(cnt[i]);
  for (int i = 0; i < int(N); i++) {
    ss[A[i]].assign(idx[i], D(L[i], R[i]));
  }
  int Q;
  cin >> Q;
  mint ans = 0;
  for (int v = 0; v < int(K); v++) ans += ss[v].query(0, cnt[v]).lor;
  while (Q--) {
    int t, i;
    cin >> t >> i;
    i--;
    ans -= ss[A[i]].query(0, cnt[A[i]]).lor;
    if (t == 1) {
      ss[A[i]].assign(idx[i], D());
    } else {
      ss[A[i]].assign(idx[i], D(L[i], R[i]));
    }
    ans += ss[A[i]].query(0, cnt[A[i]]).lor;
    cout << ans << '\n';
  }
}