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