#include <bits/stdc++.h>
using namespace std;
const int maxnum = 100001;
int Sum(const unordered_map<int, int> &m) {
  int sum = 0;
  for (const auto &pair : m) {
    sum += pair.first * pair.second;
  }
  return sum;
}
int main() {
  unordered_map<int, int> mapnum;
  int N, A;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A;
    mapnum[A]++;
  }
  int sum = Sum(mapnum);
  int Q, B, C;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    cin >> B >> C;
    if (mapnum.find(B) != mapnum.end()) {
      int &b = mapnum[B];
      int &c = mapnum[C];
      c += b;
      sum -= B * b;
      sum += C * b;
      mapnum.erase(B);
    }
    cout << sum << endl;
  }
  return 0;
}
