#include <bits/stdc++.h>
using namespace std;
int f[100000];
int main() {
  int n, m, p, ans = 0, d;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    f[p]++;
    ans += p;
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> p >> d;
    ans += -(f[p] * p) + f[p] * d;
    f[d] += f[p];
    f[p] = 0;
    cout << ans << '\n';
  }
  return 0;
}
