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