#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  map<long long, long long> mp;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    scanf("%lld", &x);
    ans += x;
    mp[x]++;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    long long x, y;
    scanf("%lld %lld", &x, &y);
    int c = mp[x];
    ans -= x * 1LL * c;
    ans += y * 1LL * c;
    mp[y] += c;
    mp[x] = 0;
    printf("%d\n", ans);
  }
  return 0;
}
