#include <bits/stdc++.h>
using namespace std;
long long inf;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T, class T2>
long long chkmin(T &a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
template <class T, class T2>
long long chkmax(T &a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T, class T2>
T mmin(T a, T2 b) {
  return a < b ? a : b;
}
template <class T, class T2>
T mmax(T a, T2 b) {
  return a > b ? a : b;
}
template <class T>
T aabs(T a) {
  return a < 0 ? -a : a;
}
template <class T>
long long dcmp(T a, T b) {
  return a > b;
}
template <long long *a>
long long cmp_a(long long first, long long second) {
  return a[first] < a[second];
}
struct __INIT__ {
  __INIT__() { memset(&inf, 0x3f, sizeof(inf)); }
} __INIT___;
namespace io {
const long long SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
long long f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char first) {
  *oS++ = first;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &first) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (first = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    first = first * 10 + (c & 15);
  first *= f;
  return 1;
}
inline bool read(char &first) {
  while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                               (iS == iT ? EOF : *iS++))
                            : *iS++)) == ' ' ||
         first == '\n' || first == '\r')
    ;
  return first != EOF;
}
inline bool read(char *first) {
  while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                                (iS == iT ? EOF : *iS++))
                             : *iS++)) == '\n' ||
         *first == ' ' || *first == '\r')
    ;
  if (*first == EOF) return 0;
  while (!(*first == '\n' || *first == ' ' || *first == '\r' || *first == EOF))
    *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                           : *iS++);
  *first = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &first, B &...second) {
  return read(first) && read(second...);
}
template <typename A>
inline bool write(A first) {
  if (!first) putc('0');
  if (first < 0) putc('-'), first = -first;
  while (first) qu[++qr] = first % 10 + '0', first /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char first) {
  putc(first);
  return 0;
}
inline bool write(const char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
inline bool write(char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A first, B... second) {
  return write(first) || write(second...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::putc;
using io ::read;
using io ::write;
long long a[300005], nx[300005], id[300005];
long long pw[300005];
pair<long long, long long> b[600005];
const long long p = 1000000007, i2 = (p + 1) >> 1;
struct smt {
  long long ls, rs, lans, rans, ans, cnt;
  smt *l, *r;
  smt(long long la, long long ra) {
    ls = la;
    rs = ra;
    lans = rans = ans = cnt = 0;
    if (ls == rs) {
      l = r = 0;
      return;
    }
    long long mid = (ls + rs) >> 1;
    l = new smt(ls, mid);
    r = new smt(mid + 1, rs);
  }
  void push_up() {
    ans = (l->ans + r->ans + l->rans * r->lans) % p;
    lans = (l->lans + r->lans * pw[l->cnt]) % p;
    rans = (r->rans + l->rans * pw[r->cnt]) % p;
    cnt = l->cnt + r->cnt;
  }
  void set(long long first) {
    if (ls == rs) {
      ans = 0;
      lans = rans = b[first].first * i2 % p;
      cnt = 1;
      return;
    }
    if (first <= l->rs)
      l->set(first);
    else
      r->set(first);
    push_up();
  }
  void unset(long long first) {
    if (ls == rs) {
      lans = rans = ans = cnt = 0;
      return;
    }
    if (first <= l->rs)
      l->unset(first);
    else
      r->unset(first);
    push_up();
  }
};
smt *rt;
signed main() {
  long long n;
  read(n);
  for (long long i = 1; i <= n; ++i) {
    read(a[i]);
    b[i] = make_pair(a[i], i);
  }
  long long q;
  read(q);
  for (long long i = 1; i <= q; ++i) {
    read(id[i], nx[i]);
    b[n + i] = make_pair(nx[i], n + i);
  }
  sort(b + 1, b + n + q + 1);
  rt = new smt(1, n + q);
  for (long long i = 1; i <= n + q; ++i) {
    if (b[i].second <= n)
      a[b[i].second] = i;
    else {
      nx[b[i].second - n] = i;
    }
  }
  pw[0] = 1;
  for (long long i = 1; i <= n; ++i) pw[i] = pw[i - 1] * i2 % p;
  for (long long i = 1; i <= n; ++i) {
    rt->set(a[i]);
  }
  write(rt->ans, '\n');
  for (long long i = 1; i <= q; ++i) {
    rt->unset(a[id[i]]);
    rt->set(a[id[i]] = nx[i]);
    write(rt->ans, '\n');
  }
  return 0;
}
