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