#include <bits/stdc++.h>
int n, m, a[1000005], t[1000005], sum, ans[1000005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    t[a[i]]++;
    sum += a[i];
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    sum += t[u] * (v - u);
    t[v] += t[u];
    t[u] = 0;
    ans[i] = sum;
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
