#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, sum = 0;
  cin >> N;
  vector<int> Nums(100010, 0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    Nums[a]++;
    sum += a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    sum += (C - B) * Nums[B];
    Nums[C] += Nums[B];
    Nums[B] = 0;
    cout << sum << endl;
  }
}
