#include <bits/stdc++.h>
using namespace std;
long int MOD = 1000000007;
int main() {
  long int sum = 0;
  int n;
  cin >> n;
  int d[100001] = {};
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    sum += a;
    d[a]++;
  }
  int q;
  cin >> q;
  int b, c;
  vector<long int> ans(q);
  for (int i = 0; i < q; ++i) {
    cin >> b >> c;
    sum -= d[b] * b;
    sum += d[b] * c;
    d[c] += d[b];
    d[b] = 0;
    ans[i] = sum;
  }
  for (int i = 0; i < q; ++i) cout << ans[i] << endl;
  return 0;
}
