#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int cnt[100001], a, b, num, n, q, x, i;
long long sum = 0;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    cnt[x]++;
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> a >> b;
    num = cnt[a];
    cnt[a] = 0;
    sum -= a * num;
    cnt[b] += num;
    sum += b * num;
    cout << sum << '\n';
  }
  return 0;
}
