#include <bits/stdc++.h>
using namespace std;
int n, q;
int ans[100005];
int b, c;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    ans[temp]++;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    ans[c] += ans[b];
    ans[b] = 0;
    long long sum = 0;
    for (int i = 1; i <= 100000; i++) {
      sum += (i * ans[i]);
    }
    cout << sum << endl;
  }
  return 0;
}
