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