#include <bits/stdc++.h>
using namespace std;
const int M = 2000007, N = 200007, mod = 1e9 + 7;
int read() {
  int ans = 0, f = 1, c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + (c - '0');
    c = getchar();
  }
  return ans * f;
}
int sum[N], s[N], ans;
struct node {
  int w, pos;
} e[N];
bool cmp(node a, node b) { return a.w < b.w; }
int n, m, cnt, sz;
int L[N], R[N], root[N];
void clear() { memset(sum, 0, sizeof(sum)); }
int lowbit(int x) { return x & -x; }
void add(int x) {
  while (x <= n) {
    sum[x]++;
    x += lowbit(x);
  }
}
int push_sum(int x) {
  int ans = 0;
  while (x) {
    ans += sum[x];
    x -= lowbit(x);
  }
  return ans;
}
struct note {
  int l, r, sz;
  int A, C, AB, BC, ABC;
} tr[M];
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].A = (tr[l].A + tr[r].A) % mod;
  tr[x].C = (tr[l].C + tr[r].C) % mod;
  tr[x].AB = (tr[l].AB + tr[r].AB + (long long)tr[l].A * tr[r].sz) % mod;
  tr[x].BC = (tr[l].BC + tr[r].BC + (long long)tr[r].C * tr[l].sz) % mod;
  tr[x].ABC = (tr[l].ABC + tr[r].ABC + (long long)tr[l].A * tr[r].BC +
               (long long)tr[l].AB * tr[r].C) %
              mod;
}
void mdf(int& x, int l, int r, int k, int v) {
  if (!x) x = ++sz;
  if (l == r) {
    tr[x].sz = 1 * v;
    tr[x].A = L[k] * v;
    tr[x].C = R[k] * v;
    tr[x].AB = tr[x].BC = tr[x].ABC = 0;
    tr[x].l = tr[x].r = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (k <= mid)
    mdf(tr[x].l, l, mid, k, v);
  else
    mdf(tr[x].r, mid + 1, r, k, v);
  up(x);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) e[i].w = read(), e[i].pos = i;
  sort(e + 1, e + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    if (e[i].w != e[i - 1].w) cnt++;
    s[e[i].pos] = cnt;
  }
  clear();
  for (int i = 1; i <= n; i++) {
    L[i] = push_sum(s[i]);
    add(s[i]);
  }
  clear();
  for (int i = n; i >= 1; i--) {
    R[i] = push_sum(s[i]);
    add(s[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans = (ans - tr[root[s[i]]].ABC + mod) % mod;
    mdf(root[s[i]], 1, n, i, 1);
    ans = (ans + tr[root[s[i]]].ABC) % mod;
  }
  int x, y;
  m = read();
  for (int i = 1; i <= m; i++) {
    x = read();
    y = read();
    ans = (ans - tr[root[s[y]]].ABC + mod) % mod;
    mdf(root[s[y]], 1, n, y, x - 1);
    ans = (ans + tr[root[s[y]]].ABC) % mod;
    printf("%d\n", ans);
  }
  return 0;
}
