#include <bits/stdc++.h>
using namespace std;
const long long int mx = 1e5 + 123;
long long int binarySearch(long long int arr[], long long int p,
                           long long int r, long long int num) {
  if (p <= r) {
    long long int mid = (p + r) / 2;
    if (arr[mid] == num) return mid;
    if (arr[mid] > num) return binarySearch(arr, p, mid - 1, num);
    if (arr[mid] < num) return binarySearch(arr, mid + 1, r, num);
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int t, i, j, a, b, x, y, e = 0, ans = 0, sum = 0;
  vector<long long int>::iterator lower, in;
  cin >> a;
  long long int c[a];
  vector<long long int> d(a);
  for (long long int i = 0; i < a; i++) {
    cin >> c[i];
    d[i] = c[i];
    sum += c[i];
  }
  cin >> b;
  while (b--) {
    cin >> x >> y;
    in = find(d.begin(), d.end(), x);
    if (in != d.end()) {
      for (i = (in - d.begin()); i < a; i++) {
        if (d[i] == x) {
          sum = sum - d[i];
          d[i] = y;
          sum = sum + d[i];
        } else
          break;
      }
      cout << sum << endl;
    } else {
      cout << sum << endl;
    }
  }
}
