#include <bits/stdc++.h>
using namespace std;
const long long MAX = pow(10, 5) + 1;
int main() {
  int n;
  cin >> n;
  int cnt[MAX];
  memset(cnt, 0, MAX);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    cnt[temp]++;
    sum += temp;
  }
  int q;
  cin >> q;
  long long bc[q];
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
