#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int anums[10005] = {};
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    anums[a]++;
    sum += (long long)a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    sum = sum + (((long long)c - (long long)b) * (long long)anums[b]);
    anums[c] += anums[b];
    anums[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
