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