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