#include <bits/stdc++.h>
using namespace std;
int arr[100001];
void solve() {
  int n, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    arr[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    sum -= x * arr[x];
    sum += y * arr[x];
    arr[y] += arr[x];
    arr[x] = 0;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
