#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  unordered_map<int, int> M;
  int sum = 0;
  for (int i = 0; i < a; i++) {
    int tmp;
    cin >> tmp;
    sum += tmp;
    M[tmp]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    sum -= x * M[x];
    sum += y * M[x];
    M[y] += M[x];
    M[x] = 0;
    cout << sum << '\n';
  }
  return 0;
}
