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