#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 20 | 1;
inline char gc() {
  static char ibuf[RLEN], *ib, *ob;
  (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ib == ob) ? EOF : *ib++;
}
inline int read() {
  char ch = gc();
  int res = 0;
  bool f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
inline long long readll() {
  char ch = gc();
  long long res = 0;
  bool f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
  return f ? res : -res;
}
inline int readstring(char *s) {
  int top = 0;
  char ch = gc();
  while (isspace(ch)) ch = gc();
  while (!isspace(ch) && ch != EOF) s[++top] = ch, ch = gc();
  return top;
}
template <class tp>
inline void chemx(tp &a, tp b) {
  a < b ? a = b : 0;
}
template <class tp>
inline void chemn(tp &a, tp b) {
  a > b ? a = b : 0;
}
const int mod = 1e9 + 7;
inline int add(int a, int b) { return (a += b) >= mod ? (a - mod) : a; }
inline int dec(int a, int b) {
  a -= b;
  return a + (a >> 31 & mod);
}
inline int mul(int a, int b) {
  static long long r;
  r = 1ll * a * b;
  return (r >= mod) ? (r % mod) : r;
}
inline void Add(int &a, int b) { (a += b) >= mod ? (a -= mod) : 0; }
inline void Dec(int &a, int b) { a -= b, a += a >> 31 & mod; }
inline void Mul(int &a, int b) {
  static long long r;
  r = 1ll * a * b;
  a = (r >= mod) ? (r % mod) : r;
}
inline int ksm(int a, int b, int res = 1) {
  if (a == 0 && b == 0) return 0;
  for (; b; b >>= 1, Mul(a, a)) (b & 1) && (Mul(res, a), 1);
  return res;
}
inline int Inv(int x) { return ksm(x, mod - 2); }
inline int fix(int x) { return (x < 0) ? x + mod : x; }
const int N = 300005;
int pw[N], ip[N];
pair<int, int> p[N << 1];
int pos[N << 1], upd[N], n, q;
namespace Seg {
const int N = ::N << 3;
int ls[N], rs[N], s[N], siz[N];
inline void pushup(int u) {
  siz[u] = siz[(u << 1)] + siz[((u << 1) | 1)];
  s[u] = add(add(s[(u << 1)], s[((u << 1) | 1)]),
             mul(mul(ls[(u << 1)], rs[((u << 1) | 1)]), ip[siz[(u << 1)]]));
  ls[u] = add(ls[(u << 1)], mul(ls[((u << 1) | 1)], pw[siz[(u << 1)]]));
  rs[u] = add(rs[(u << 1)], mul(rs[((u << 1) | 1)], ip[siz[(u << 1)]]));
}
void build(int u, int l, int r) {
  if (l == r) {
    if (p[l].second <= n)
      s[u] = 0, ls[u] = p[l].first, rs[u] = mul(p[l].first, ip[1]), siz[u] = 1;
    return;
  }
  build((u << 1), l, ((l + r) >> 1)),
      build(((u << 1) | 1), ((l + r) >> 1) + 1, r);
  pushup(u);
}
void update(int u, int l, int r, int ps, int kd) {
  if (l == r) {
    if (kd == 1)
      s[u] = 0, ls[u] = p[l].first, rs[u] = mul(p[l].first, ip[1]), siz[u] = 1;
    else
      s[u] = ls[u] = rs[u] = siz[u] = 0;
    return;
  }
  if (ps <= ((l + r) >> 1))
    update((u << 1), l, ((l + r) >> 1), ps, kd);
  else
    update(((u << 1) | 1), ((l + r) >> 1) + 1, r, ps, kd);
  pushup(u);
}
}  // namespace Seg
int main() {
  pw[0] = ip[0] = 1;
  for (int i = 1; i < N; i++) pw[i] = mul(pw[i - 1], 2);
  for (int i = 1, iv = Inv(2); i < N; i++) ip[i] = mul(ip[i - 1], iv);
  n = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    p[i] = pair<int, int>(x, i);
  }
  q = read();
  for (int i = 1; i <= q; i++) {
    int t = read(), x = read();
    upd[i] = t;
    p[i + n] = pair<int, int>(x, i + n);
  }
  sort(p + 1, p + n + q + 1);
  for (int i = 1; i <= n + q; i++) pos[p[i].second] = i;
  Seg::build(1, 1, n + q);
  cout << Seg::s[1] << '\n';
  for (int i = 1; i <= q; i++) {
    Seg::update(1, 1, n + q, pos[upd[i]], 0);
    pos[upd[i]] = pos[n + i];
    Seg::update(1, 1, n + q, pos[upd[i]], 1);
    cout << Seg::s[1] << '\n';
  }
}
