#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int ary[100001] = {};
  int num;
  cin >> num;
  unsigned long long sum = 0;
  for (int i = 0; i < num; i++) {
    int tmp;
    cin >> tmp;
    ary[tmp]++;
    sum += tmp;
  }
  int CNT;
  cin >> CNT;
  for (int i = 0; i < CNT; i++) {
    int b, c;
    cin >> b >> c;
    sum = sum - b * ary[b] + c * ary[b];
    ary[c] = ary[c] + ary[b];
    ary[b] = 0;
    cout << sum << '\n';
  }
  return 0;
}
