#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;
int main(void) {
  int n, q;
  cin >> n;
  int hash[100009] = {0};
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    hash[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b[i] >> c[i];
    sum -= b[i] * hash[b[i]];
    sum += c[i] * hash[b[i]];
    cout << sum << endl;
    hash[c[i]] += hash[b[i]];
    hash[b[i]] = 0;
  }
  return 0;
}
