#include <bits/stdc++.h>
using namespace std;
const long long int LINF = 1e18, mod = 1e9 + 7;
void Bl0ck_M0mb0();
signed main() {
  Bl0ck_M0mb0();
  long long int t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    long long int A[n + 1], sum = 0;
    map<long long int, set<long long int> > ip;
    for (long long int i = 1; i <= n; i++) {
      cin >> A[i];
      sum += A[i];
      ip[A[i]].insert(i);
    }
    long long int q;
    cin >> q;
    for (long long int i = 1; i <= q; i++) {
      long long int bi, ci;
      cin >> bi >> ci;
      long long int sz = ip[bi].size();
      ip[ci].insert(ip[bi].begin(), ip[bi].end());
      ip.erase(ip.find(bi));
      sum -= sz * bi;
      sum += sz * ci;
      cout << sum << endl;
    }
  }
  return 0;
}
void Bl0ck_M0mb0() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
