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 Int = long long;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
};
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cerr << *i << " ";
  cerr << endl;
}
template <class T>
bool chmin(T &t, const T &f) {
  if (t > f) {
    t = f;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T &t, const T &f) {
  if (t < f) {
    t = f;
    return true;
  }
  return false;
}
template <int M_>
struct ModInt {
  static constexpr int M = M_;
  int x;
  constexpr ModInt() : x(0) {}
  constexpr ModInt(long long x_) : x(x_ % M) {
    if (x < 0) x += M;
  }
  ModInt &operator+=(const ModInt &a) {
    x += a.x;
    if (x >= M) x -= M;
    return *this;
  }
  ModInt &operator-=(const ModInt &a) {
    x -= a.x;
    if (x < 0) x += M;
    return *this;
  }
  ModInt &operator*=(const ModInt &a) {
    x = static_cast<int>((static_cast<long long>(x) * a.x) % M);
    return *this;
  }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  ModInt operator-() const { return ModInt(-x); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt x2 = x, xe = 1;
    for (; e; e >>= 1) {
      if (e & 1) xe *= x2;
      x2 *= x2;
    }
    return xe;
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (;;) {
      t = a / b;
      a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a;
      b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  friend ModInt operator+(long long a, const ModInt &b) {
    return (ModInt(a) += b);
  }
  friend ModInt operator-(long long a, const ModInt &b) {
    return (ModInt(a) -= b);
  }
  friend ModInt operator*(long long a, const ModInt &b) {
    return (ModInt(a) *= b);
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) {
    return os << a.x;
  }
};
constexpr int MO = 1000000007;
using Mint = ModInt<MO>;
template <class T>
void bAdd(vector<T> &bit, int pos, T val) {
  for (int x = pos; x < (int)bit.size(); x |= x + 1) {
    bit[x] += val;
  }
}
template <class T>
T bSum(const vector<T> &bit, int pos) {
  T ret = 0;
  for (int x = pos - 1; x >= 0; x = (x & (x + 1)) - 1) {
    ret += bit[x];
  }
  return ret;
}
template <class T, class S, class OpTT, class OpST, class OpSS>
struct SegmentTree {
  const OpTT opTT;
  const OpST opST;
  const OpSS opSS;
  const T idT;
  const S idS;
  int n;
  vector<T> ts;
  vector<S> ss;
  SegmentTree(int n_, const OpTT opTT, const OpST opST, const OpSS opSS,
              const T &idT, const S &idS)
      : opTT(opTT), opST(opST), opSS(opSS), idT(idT), idS(idS) {
    for (n = 1; n < n_; n <<= 1) {
    }
    ts.assign(n << 1, idT);
    ss.assign(n << 1, idS);
  }
  T &at(int a) { return ts[n + a]; }
  void build() {
    for (int a = n; --a;) ts[a] = opTT(ts[a << 1], ts[a << 1 | 1]);
  }
  T query(int a, int b, const S &s) { return query(1, 0, n, a, b, s); }

 private:
  T query(int u, int l, int r, int a, int b, const S &s) {
    if (a < l) a = l;
    if (b > r) b = r;
    if (a >= b) return idT;
    if (a == l && b == r) {
      ts[u] = opST(s, ts[u], r - l);
      ss[u] = opSS(s, ss[u]);
      return ts[u];
    }
    const int uL = u << 1, uR = u << 1 | 1;
    const int mid = (l + r) >> 1;
    {
      ts[uL] = opST(ss[u], ts[uL], mid - l);
      ts[uR] = opST(ss[u], ts[uR], r - mid);
      ss[uL] = opSS(ss[u], ss[uL]);
      ss[uR] = opSS(ss[u], ss[uR]);
      ss[u] = idS;
    }
    const T resL = query(uL, l, mid, a, b, s);
    const T resR = query(uR, mid, r, a, b, s);
    ts[u] = opTT(ts[uL], ts[uR]);
    return opTT(resL, resR);
  }
};
int N;
vector<Int> A;
int M;
vector<int> T, X;
int main() {
  for (; ~scanf("%d", &N);) {
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%lld", &A[i]);
    }
    scanf("%d", &M);
    T.resize(M);
    X.resize(M);
    for (int m = 0; m < M; ++m) {
      scanf("%d%d", &T[m], &X[m]);
      --X[m];
    }
    auto as = A;
    sort(as.begin(), as.end());
    as.erase(unique(as.begin(), as.end()), as.end());
    const int asLen = as.size();
    vector<vector<int>> iss(asLen);
    vector<int> es(N), fs(N);
    for (int i = 0; i < N; ++i) {
      const int e = lower_bound(as.begin(), as.end(), A[i]) - as.begin();
      es[i] = e;
      fs[i] = iss[e].size();
      iss[e].push_back(i);
    }
    vector<Int> ls(N), rs(N);
    {
      vector<Int> bit(asLen);
      fill(bit.begin(), bit.end(), 0);
      for (int i = 0; i < N; ++i) {
        ls[i] = bSum(bit, es[i] + 1);
        bAdd<Int>(bit, es[i], 1);
      }
      fill(bit.begin(), bit.end(), 0);
      for (int i = N; i--;) {
        rs[i] = bSum(bit, es[i] + 1);
        bAdd<Int>(bit, es[i], 1);
      }
    }
    vector<vector<Int>> bits1(asLen);
    vector<vector<Int>> bitsL(asLen);
    vector<vector<Int>> bitsR(asLen);
    using Entry = pair<Int, Int>;
    auto opTT = [](const Entry &ta, const Entry &tb) {
      return Entry(ta.first + tb.first, ta.second + tb.second);
    };
    auto opST = [](const Entry &s, const Entry &t, int sz) {
      return Entry(t.first + s.first * (t.second + s.second),
                   t.second + s.second);
    };
    using ST = SegmentTree<Entry, Entry, decltype(opTT), decltype(opST),
                           decltype(opTT)>;
    vector<ST *> segL(asLen);
    vector<ST *> segR(asLen);
    for (int e = 0; e < asLen; ++e) {
      bits1[e].assign(iss[e].size(), 0);
      bitsL[e].assign(iss[e].size(), 0);
      bitsR[e].assign(iss[e].size(), 0);
      segL[e] =
          new ST(iss[e].size(), opTT, opST, opTT, Entry(0, 0), Entry(0, 0));
      segR[e] =
          new ST(iss[e].size(), opTT, opST, opTT, Entry(0, 0), Entry(0, 0));
    }
    auto calc = [&](int i) {
      Mint ret = 0;
      const int e = es[i], f = fs[i];
      const Mint x = bSum(bits1[e], f);
      const Mint ll = bSum(bitsL[e], f);
      const Mint rr = bSum(bitsR[e], iss[e].size()) - bSum(bitsR[e], f);
      const Mint sl = segL[e]->query(0, f, Entry(0, 0)).first;
      const Mint sr = segR[e]->query(f + 1, iss[e].size(), Entry(0, 0)).first;
      ret += ls[i] * (sr - x * rr);
      ret += ll * rr;
      ret += ((x - 1) * ll - sl) * rs[i];
      return ret;
    };
    Mint ans = 0;
    auto add = [&](int i) {
      ans += calc(i);
      const int e = es[i], f = fs[i];
      const Int x = bSum(bits1[e], f);
      bAdd<Int>(bits1[e], f, 1);
      bAdd<Int>(bitsL[e], f, ls[i]);
      bAdd<Int>(bitsR[e], f, rs[i]);
      segL[e]->query(f, f + 1, Entry(0, ls[i]));
      segL[e]->query(f, f + 1, Entry(x, 0));
      segL[e]->query(f + 1, iss[e].size(), Entry(1, 0));
      segR[e]->query(f, f + 1, Entry(x, rs[i]));
      segR[e]->query(f + 1, iss[e].size(), Entry(1, 0));
    };
    auto rem = [&](int i) {
      const int e = es[i], f = fs[i];
      const Int x = bSum(bits1[e], f);
      bAdd<Int>(bits1[e], f, -1);
      bAdd<Int>(bitsL[e], f, -ls[i]);
      bAdd<Int>(bitsR[e], f, -rs[i]);
      segL[e]->query(f, f + 1, Entry(-x, 0));
      segL[e]->query(f, f + 1, Entry(0, -ls[i]));
      segL[e]->query(f + 1, iss[e].size(), Entry(-1, 0));
      segR[e]->query(f, f + 1, Entry(-x, 0));
      segR[e]->query(f, f + 1, Entry(0, -rs[i]));
      segR[e]->query(f + 1, iss[e].size(), Entry(-1, 0));
      ans -= calc(i);
    };
    for (int i = 0; i < N; ++i) {
      add(i);
    }
    for (int m = 0; m < M; ++m) {
      if (T[m] == 1) {
        rem(X[m]);
      } else {
        add(X[m]);
      }
      printf("%d\n", ans.x);
    }
  }
  return 0;
}