#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, q;
int freq[MAXN];
int main() {
  scanf("%d", &n);
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    int v;
    scanf("%d", &v);
    ans += v;
    freq[v]++;
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int b, c;
    scanf("%d %d", &b, &c);
    long long int qtd = freq[b];
    ans -= freq[b] * b;
    ans += freq[b] * c;
    freq[c] += qtd;
    freq[b] = 0;
    printf("%lld\n", ans);
  }
}
