#include <bits/stdc++.h>
using namespace std;
int n, q;
int a[200000];
int b, c;
map<int, int> mp;
long long int res = 0;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    res += a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    int cnt = mp[b];
    int cnt2 = mp[c];
    mp[c] += cnt;
    mp[b] = 0;
    res -= b * cnt;
    res += c * cnt;
    cout << res << endl;
  }
  return 0;
}
