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