#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
int cnt[MAX];
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    cnt[x - 1]++;
  }
  int c, u, v;
  cin >> c;
  while (c--) {
    cin >> u >> v;
    sum += v * cnt[u - 1];
    sum -= u * cnt[u - 1];
    cnt[v - 1] += cnt[u - 1];
    cnt[u - 1] = 0;
    cout << sum << endl;
  }
}
