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