#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 5;
long long freq[NMAX], x, sum, y, t, n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    freq[x]++;
    sum += x;
  }
  cin >> t;
  while (t--) {
    cin >> x >> y;
    sum = sum - freq[x] * x + freq[x] * y;
    freq[y] += freq[x];
    cout << sum << '\n';
  }
  return 0;
}
