#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[100010];
int b[100010];
int c[100010];
int dCount[100010];
long long total;
int main() {
  for (int i = 0; i <= 100000; i++) dCount[i] = 0;
  scanf("%d", &n);
  total = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &(a[i]));
    dCount[a[i]]++;
    total = total + a[i];
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &(b[i]), &(c[i]));
    int count = dCount[b[i]];
    total = total - b[i] * count;
    dCount[b[i]] = 0;
    total = total + c[i] * count;
    dCount[c[i]] = dCount[c[i]] + count;
    printf("%lld\n", total);
  }
  return 0;
}
