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