#include <bits/stdc++.h>
using namespace std;
const int N = 600600;
const int Mod = 1e9 + 7;
const int Inv2 = 500000004;
int Two[N][2];
void add_self(int& x, int y) {
  if ((x += y) >= Mod) x -= Mod;
}
void sub_self(int& x, int y) {
  if ((x -= y) < 0) x += Mod;
}
int add(int x, int y) { return add_self(x, y), x; }
int sub(int x, int y) { return sub_self(x, y), x; }
int mul(int x, int y) { return (long long)x * y % Mod; }
template <typename type>
struct SegmentTreeWithoutLazyPropagation {
 private:
  const type E = 0;

 private:
  static const int Nax = 4 * N;

 private:
  int n;

 private:
  type Tree[Nax];

 public:
  SegmentTreeWithoutLazyPropagation(int n = 0) : n(n) {
    for (int Node = 0; Node < Nax; Node++) Tree[Node] = E;
  }

 private:
  type Unite(type x, type y) { return x + y; }

 private:
  void Merge(int Node) {
    Tree[Node] = Unite(Tree[(Node << 1)], Tree[(Node << 1 | 1)]);
  }

 public:
  void Build(const vector<type>& a) {
    Clear();
    n = a.size();
    Build(a, 1, 0, n - 1);
  }

 private:
  void Build(const vector<type>& a, int Node, int L, int R) {
    Tree[Node] = E;
    if (L == R) return void(Tree[Node] = a[L]);
    Build(a, (Node << 1), L, ((L + R) >> 1));
    Build(a, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  void Update(int i, type x) {
    if (n <= 0) return;
    Update(i, x, 1, 0, n - 1);
  }

 private:
  void Update(int i, type x, int Node, int L, int R) {
    if (i < L || R < i) return;
    if (L == R) return void(Tree[Node] = x);
    Update(i, x, (Node << 1), L, ((L + R) >> 1));
    Update(i, x, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  type Query(int i, int j) {
    if (n <= 0 || i > j) return E;
    return Query(i, j, 1, 0, n - 1);
  }

 private:
  type Query(int i, int j, int Node, int L, int R) {
    if (j < L || R < i) return E;
    if (i <= L && R <= j) return Tree[Node];
    return Unite(Query(i, j, (Node << 1), L, ((L + R) >> 1)),
                 Query(i, j, (Node << 1 | 1), ((L + R) >> 1) + 1, R));
  }

 public:
  void Clear() {
    for (int Node = 0; Node <= 4 * n; Node++) Tree[Node] = E;
    n = 0;
  }
};
template <typename type>
struct SegmentTreeWithLazyPropagation {
 private:
  const type E = 0;

 private:
  const type EL = 1;

 private:
  static const int Nax = 4 * N;

 private:
  int n;

 private:
  type Tree[Nax];

 private:
  type Lazy[Nax];

 public:
  SegmentTreeWithLazyPropagation(int n = 0) : n(n) {
    for (int Node = 0; Node < Nax; Node++) Tree[Node] = E, Lazy[Node] = EL;
  }

 private:
  type Unite(type x, type y) { return add(x, y); }

 private:
  void Merge(int Node) {
    Tree[Node] = Unite(Tree[(Node << 1)], Tree[(Node << 1 | 1)]);
  }

 private:
  void PushLazy(int Node, int Len) {
    if (Lazy[Node] != EL) {
      Tree[Node] = mul(Tree[Node], Lazy[Node]);
      if (Len > 1) {
        Lazy[(Node << 1)] = mul(Lazy[(Node << 1)], Lazy[Node]);
        Lazy[(Node << 1 | 1)] = mul(Lazy[(Node << 1 | 1)], Lazy[Node]);
      }
      Lazy[Node] = EL;
    }
  }

 public:
  void Build(const vector<type>& a) {
    Clear();
    n = a.size();
    Build(a, 1, 0, n - 1);
  }

 private:
  void Build(const vector<type>& a, int Node, int L, int R) {
    Tree[Node] = E, Lazy[Node] = EL;
    if (L == R) return void(Tree[Node] = a[L]);
    Build(a, (Node << 1), L, ((L + R) >> 1));
    Build(a, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  void Update(int i, int j, type x) {
    if (n <= 0 || i > j) return;
    Update(i, j, x, 1, 0, n - 1);
  }

 private:
  void Update(int i, int j, type x, int Node, int L, int R) {
    PushLazy(Node, R - L + 1);
    if (j < L || R < i) return;
    if (i <= L && R <= j) return Lazy[Node] = x, PushLazy(Node, R - L + 1);
    Update(i, j, x, (Node << 1), L, ((L + R) >> 1));
    Update(i, j, x, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  void Update(int i, type x) {
    if (n <= 0) return;
    Update(i, x, 1, 0, n - 1);
  }

 private:
  void Update(int i, type x, int Node, int L, int R) {
    PushLazy(Node, R - L + 1);
    if (i < L || R < i) return;
    if (L == R) return void(Tree[Node] = x);
    Update(i, x, (Node << 1), L, ((L + R) >> 1));
    Update(i, x, (Node << 1 | 1), ((L + R) >> 1) + 1, R);
    Merge(Node);
  }

 public:
  type Query(int i, int j) {
    if (n <= 0 || i > j) return E;
    return Query(i, j, 1, 0, n - 1);
  }

 private:
  type Query(int i, int j, int Node, int L, int R) {
    PushLazy(Node, R - L + 1);
    if (j < L || R < i) return E;
    if (i <= L && R <= j) return Tree[Node];
    return Unite(Query(i, j, (Node << 1), L, ((L + R) >> 1)),
                 Query(i, j, (Node << 1 | 1), ((L + R) >> 1) + 1, R));
  }

 public:
  void Clear() {
    for (int Node = 0; Node <= 4 * n; Node++) Tree[Node] = E, Lazy[Node] = EL;
    n = 0;
  }
};
SegmentTreeWithLazyPropagation<int> myTree[2];
SegmentTreeWithoutLazyPropagation<int> CntTree;
int main() {
  Two[0][0] = Two[0][1] = 1;
  for (int i = 1; i < N; i++) Two[i][0] = mul(2, Two[i - 1][0]);
  for (int i = 1; i < N; i++) Two[i][1] = mul(Inv2, Two[i - 1][1]);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& x : a) scanf("%d", &x);
  int q;
  cin >> q;
  vector<pair<int, int> > Q(q);
  for (pair<int, int>& x : Q) scanf("%d%d", &x.first, &x.second);
  vector<pair<int, int> > A;
  for (int i = 0; i < n; i++) A.emplace_back(a[i], i);
  for (int i = 0; i < q; i++) A.emplace_back(Q[i].second, i + n);
  sort(A.begin(), A.end());
  vector<int> Where(n + q);
  for (int i = 0; i < n + q; i++) Where[A[i].second] = i;
  CntTree.Build(vector<int>(n + q));
  for (int i = 0; i < n + q; i++)
    if (A[i].second < n) CntTree.Update(i, 1);
  for (int j = 0; j < 2; j++) {
    vector<int> b(n + q);
    for (int i = 0, r = 0; i < n + q; i++)
      if (A[i].second < n) b[i] = mul(Two[r++][j], A[i].first);
    myTree[j].Build(b);
  }
  int Ans = 0;
  for (int i = 0, r = 0; i < n + q; i++)
    if (A[i].second < n)
      add_self(Ans,
               mul(mul(Two[r++][1], A[i].first), myTree[0].Query(0, i - 1)));
  printf("%d\n", mul(Inv2, Ans));
  vector<int> Last(n);
  for (int i = 0; i < n; i++) Last[i] = Where[i];
  for (int j = 0; j < q; j++) {
    int i = Q[j].first;
    int x = Q[j].second;
    int k = Where[j + n];
    {
      int I = --i;
      i = Last[i];
      Last[I] = k;
    }
    sub_self(Ans, mul(mul(Two[CntTree.Query(0, i - 1)][1], A[i].first),
                      myTree[0].Query(0, i - 1)));
    sub_self(Ans, mul(mul(Two[CntTree.Query(0, i - 1)][0], A[i].first),
                      myTree[1].Query(i + 1, n + q - 1)));
    sub_self(Ans,
             mul(myTree[0].Query(0, i - 1), myTree[1].Query(i + 1, n + q - 1)));
    CntTree.Update(i, 0);
    myTree[0].Update(i, 0);
    myTree[1].Update(i, 0);
    myTree[0].Update(i + 1, n + q - 1, Inv2);
    myTree[1].Update(i + 1, n + q - 1, 2);
    add_self(Ans,
             mul(myTree[0].Query(0, i - 1), myTree[1].Query(i + 1, n + q - 1)));
    sub_self(Ans,
             mul(myTree[0].Query(0, k - 1), myTree[1].Query(k + 1, n + q - 1)));
    CntTree.Update(k, 1);
    myTree[0].Update(k + 1, n + q - 1, 2);
    myTree[1].Update(k + 1, n + q - 1, Inv2);
    myTree[0].Update(k, mul(Two[CntTree.Query(0, k - 1)][0], A[k].first));
    myTree[1].Update(k, mul(Two[CntTree.Query(0, k - 1)][1], A[k].first));
    add_self(Ans,
             mul(myTree[0].Query(0, k - 1), myTree[1].Query(k + 1, n + q - 1)));
    add_self(Ans, mul(mul(Two[CntTree.Query(0, k - 1)][1], A[k].first),
                      myTree[0].Query(0, k - 1)));
    add_self(Ans, mul(mul(Two[CntTree.Query(0, k - 1)][0], A[k].first),
                      myTree[1].Query(k + 1, n + q - 1)));
    printf("%d\n", mul(Inv2, Ans));
  }
}
