#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, a[100000], i, x, y, t, s, d;
  scanf("%lld", &n);
  s = 0;
  for (i = 0; i < n; i++) {
    scanf("%lld", &d);
    a[d]++;
    s += d;
  }
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &x, &y);
    a[y] += a[x];
    s += (y - x) * a[x];
    a[x] = 0;
    printf("%lld\n", s);
  }
}
