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