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