#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int N, Q, a, b, mp[MAX];
long long sum;
int main(int argc, char** argv) {
  scanf("%d", &N);
  for (int i = (0); i < (N); i++) {
    scanf("%d", &a);
    mp[a]++;
    sum += a;
  }
  scanf("%d", &Q);
  for (int q = (0); q < (Q); q++) {
    scanf("%d%d", &a, &b);
    sum -= mp[a] * a;
    sum += mp[a] * b;
    mp[b] += mp[a];
    mp[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
