#include <bits/stdc++.h>
using namespace std;
bool com(pair<long long int, long long int> x,
         pair<long long int, long long int> y) {
  return x.first < y.first;
}
void solve() {
  int n;
  cin >> n;
  vector<int> frq(1e5 + 7, 0), a(n);
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    frq[a[i]]++;
    sum += a[i];
  }
  int q, b, c;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    sum -= (long long)(b * frq[b]);
    sum += (long long)(c * frq[b]);
    frq[c] += frq[b];
    frq[b] = 0;
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
