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