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