#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int n, m, cnt, sum, x, y;
int num[N], t[N], L[N], R[N], root[N], ans;
struct node {
  int w, pos;
} a[N];
struct tree {
  int l, r, sz, s[6];
} tr[N * 10];
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (x == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
bool cmp(node a, node b) { return a.w < b.w; }
int lowbit(int x) { return x & (-x); }
void insert(int x) {
  while (x <= n) {
    t[x]++;
    x += lowbit(x);
  }
}
int query(int x) {
  int ans = 0;
  while (x) {
    ans += t[x];
    x -= lowbit(x);
  }
  return ans;
}
void up(int x) {
  int l = tr[x].l, r = tr[x].r;
  tr[x].sz = (tr[l].sz + tr[r].sz) % mod;
  tr[x].s[1] = (tr[l].s[1] + tr[r].s[1]) % mod;
  tr[x].s[5] = (tr[l].s[5] + tr[r].s[5]) % mod;
  tr[x].s[2] =
      (tr[l].s[2] + tr[r].s[2] + (long long)tr[l].s[1] * tr[r].sz) % mod;
  tr[x].s[4] =
      (tr[l].s[4] + tr[r].s[4] + (long long)tr[l].sz * tr[r].s[5]) % mod;
  tr[x].s[3] = (tr[l].s[3] + tr[r].s[3] + (long long)tr[l].s[1] * tr[r].s[4] +
                (long long)tr[l].s[2] * tr[r].s[5]) %
               mod;
}
void change(int &x, int l, int r, int pos, int v) {
  if (x == 0) x = ++sum;
  if (l == r) {
    tr[x].sz = v * 1;
    tr[x].s[1] = v * L[pos];
    tr[x].s[5] = v * R[pos];
    tr[x].s[2] = tr[x].s[3] = tr[x].s[4] = 0;
    tr[x].l = tr[x].r = 0;
    return;
  } else {
    int mid = (l + r) >> 1;
    if (pos <= mid)
      change(tr[x].l, l, mid, pos, v);
    else
      change(tr[x].r, mid + 1, r, pos, v);
    up(x);
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i].w = read(), a[i].pos = i;
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (a[i].w != a[i - 1].w) cnt++;
    num[a[i].pos] = cnt;
  }
  for (int i = 1; i <= n; i++) L[i] = query(num[i]), insert(num[i]);
  memset(t, 0, sizeof(t));
  for (int i = n; i >= 1; i--) R[i] = query(num[i]), insert(num[i]);
  for (int i = 1; i <= n; i++) {
    ans = (ans - tr[root[num[i]]].s[3] + mod) % mod;
    change(root[num[i]], 1, n, i, 1);
    ans = (ans + tr[root[num[i]]].s[3]) % mod;
  }
  m = read();
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    ans = (ans - tr[root[num[y]]].s[3] + mod) % mod;
    change(root[num[y]], 1, n, y, x - 1);
    ans = (ans + tr[root[num[y]]].s[3]) % mod;
    printf("%d\n", ans);
  }
  return 0;
}
