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