#include <bits/stdc++.h>
using namespace std;
int n, a[3000003], d[3000003], sum = 0;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    d[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum -= (d[x] * x);
    sum += (d[x] * y);
    d[y] += d[x];
    d[x] = 0;
    cout << sum << '\n';
  }
}
