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