#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> num(n);
  for (int i = 0; i < n; i++) {
    cin >> num.at(i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int before, after;
    cin >> before >> after;
    for (int j = 0; j < n; j++) {
      if (num.at(j) == before) {
        num.at(j) = after;
      }
    }
    long output = 0;
    for (int j = 0; j < n; j++) {
      output += num.at(j);
    }
    cout << output << endl;
  }
}
