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