#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  multiset<int> A;
  map<int, int> mokuji;
  int Q;
  int B[100050];
  int C[100050];
  int sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (mokuji.count(a)) {
      mokuji[a] += 1;
    } else {
      mokuji[a] = 1;
    }
    sum += a;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    if (mokuji.count(B[i])) {
      if (mokuji.count(C[i])) {
        mokuji[C[i]] += mokuji[B[i]];
      } else {
        mokuji[C[i]] = mokuji[B[i]];
      }
      sum -= B[i] * mokuji[B[i]];
      sum += C[i] * mokuji[B[i]];
      mokuji.erase(B[i]);
    }
    cout << sum << endl;
  }
}
