#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, fr[N];
long long sum;
int main() {
  scanf("%d", &n);
  for (int i = 0, x; i < n; ++i) {
    scanf("%d", &x);
    fr[x]++;
    sum += x;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    sum -= fr[a] * a;
    sum += fr[a] * b;
    fr[b] += fr[a];
    fr[a] = 0;
    printf("%lld\n", sum);
  }
}
