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