#include <bits/stdc++.h>
using namespace std;
int freq[100000 + 5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, i, x, y, q;
  long long sum = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> x;
    freq[x]++;
    sum += x;
  }
  cin >> q;
  while (q-- > 00) {
    cin >> x >> y;
    sum -= 1LL * freq[x] * x;
    sum -= 1LL * freq[y] * y;
    freq[y] += freq[x];
    freq[x] = 0;
    sum += 1LL * freq[y];
    cout << sum << "\n";
  }
  return 0;
}
