#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 1e9 + 7;
const long long mod2 = 998244353;
const int INF = 0x3f3f3f3f;
int n, q;
long long a[100005], x, y, ans, f[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ans += a[i];
    f[a[i]]++;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> x >> y;
    f[y] += f[x];
    ans += f[x] * (y - x);
    f[x] = 0;
    printf("%lld\n", ans);
  }
  return 0;
}
