#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
  int n, sum = 0;
  cin >> n;
  vector<ll> a(n), data(100010, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i], sum += a[i];
    data[a[i]]++;
  }
  int Q;
  cin >> Q;
  vector<ll> ans(Q);
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    ans[i] = sum + (c - b) * data[b];
    sum = ans[i];
    data[c] += data[b];
    data[b] = 0;
  }
  for (int i = 0; i < Q; i++) cout << ans[i] << endl;
}
