#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int tc = 1;
  while (tc--) {
    long long int n;
    cin >> n;
    vector<int> fre(100005, 0);
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      fre[a[i]]++;
      sum += a[i];
    }
    int q;
    cin >> q;
    while (q--) {
      int b, c;
      cin >> b >> c;
      sum = sum - (fre[b] * b) + (fre[b] * c);
      fre[c] += fre[b];
      fre[b] = 0;
      cout << sum << "\n";
    }
  }
  return 0;
}
