#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, s = 0;
  cin >> n;
  vector<long long int> arr;
  map<int, int> mp;
  for (int i = (int)0; i < (int)n; ++i) {
    int ele;
    cin >> ele;
    s += ele;
    mp[ele]++;
    arr.push_back(ele);
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int s1 = 0, s2 = 0;
    long long int o, n;
    cin >> o >> n;
    s1 = o * (mp.find(o)->second);
    s2 = n * (mp.find(o)->second);
    if (mp.find(n)->second != 0) {
      mp.find(n)->second += mp.find(o)->second;
    } else {
      mp.insert(make_pair(n, mp.find(o)->second));
    }
    mp.find(o)->second = 0;
    s = s + s2 - s1;
    cout << s << "\n";
  }
}
