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