#include <bits/stdc++.h>
using namespace std;
long long times[100001], n, q, sum;
signed main() {
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    times[x]++;
    sum += x;
  }
  scanf("%lld", &q);
  while (q--) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    sum += (y - x) * times[x];
    cout << sum << endl;
    times[y] += times[x];
  }
  return 0;
}
