#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, r, s = 0, b, c, j;
  scanf("%lld", &n);
  long long int a[n + 10];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  cin >> m;
  long long int f[m + 10];
  for (i = 0; i < m; i++) {
    cin >> b >> c;
    for (j = 0; j < n; j++) {
      if (a[j] == b) {
        s = ((s - b) + c);
        a[j] = c;
      }
    }
    f[i] = s;
  }
  for (i = 0; i < m; i++) cout << f[i] << endl;
}
