#include <bits/stdc++.h>
using namespace std;
using ipair = pair<int, int>;
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };
const int MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int cnt[100002];
  long long int sum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (q); ++i) cin >> b[i] >> c[i];
  for (int i = 0; i < (q); ++i) {
    sum = sum + (c[i] - b[i]) * cnt[b[i]];
    cnt[c[i]] = cnt[c[i]] + cnt[b[i]];
    cnt[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
