#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  vector<int> count(1e5 + 5);
  long long sum = 0;
  for (long long i = 0; i < long long(n); i++) {
    cin >> v[i];
    count[v[i]]++;
    sum += v[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int co = count[b];
    sum -= (co * b);
    sum += (co * c);
    count[c] += co;
    cout << sum << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  solve();
}
