#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << "[ " << *it << " = " << a << " ] ";
  err(++it, args...);
}
class BIT {
 public:
  vector<long long int> bit;
  long long int N;
  BIT(long long int arr[], long long int n) {
    N = n;
    bit.assign(N + 1, 0);
    for (long long int i = 1; i <= N; i++) {
      updateBIT(arr[i - 1], i);
    }
  }
  void updateBIT(long long int val, long long int idx) {
    while (idx < N + 1) {
      bit[idx] += val;
      idx = getNext(idx);
    }
  }
  void update(long long int val, long long int idx) {
    long long int diff = val - bit[idx];
    updateBIT(diff, idx);
  }
  long long int getNext(long long int idx) { return idx + (idx & -idx); }
  long long int getSum(long long int idx) {
    idx++;
    long long int sum = 0;
    while (idx > 0) {
      sum += bit[idx];
      idx = getParent(idx);
    }
    return sum;
  }
  long long int getParent(long long int idx) { return idx - (idx & -idx); }
};
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    set<long long int> s;
    for (long long int& i : a) {
      cin >> i;
      s.insert(i);
    }
    BIT bit(a, n);
    long long int Q;
    cin >> Q;
    while (Q--) {
      long long int aa, b;
      cin >> aa >> b;
      for (long long int i = 0; i < n; i++) {
        if (a[i] == aa) {
          a[i] = b;
          bit.updateBIT(b - aa, i + 1);
        }
      }
      long long int val = bit.getSum(n - 1);
      cout << val << '\n';
    }
  }
  return 0;
}
