#include <bits/stdc++.h>
using namespace std;
int main() {
  freopen("in.txt", "r", stdin);
  int n;
  cin >> n;
  int cnt[1000000];
  int arr1[1000000];
  memset(cnt, 0, sizeof(cnt));
  memset(arr1, 0, sizeof(arr1));
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    int tmp;
    cin >> tmp;
    sum += tmp;
    arr1[i] = tmp;
    cnt[tmp]++;
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    long long a, b;
    cin >> a >> b;
    sum -= (cnt[a] * a);
    sum += (cnt[a] * b);
    cnt[b] += cnt[a];
    cnt[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
