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