#include <bits/stdc++.h>
using namespace std;
vector<int> cnt(100005, 0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  unsigned long long sum = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++cnt[a];
    sum += a;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int prev = cnt[b];
    cnt[b] += cnt[a];
    sum -= cnt[a] * a;
    cnt[a] = 0;
    sum += (cnt[b] - prev) * b;
    cout << sum << '\n';
  }
}
