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