#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  int a = 0;
  cin >> a;
  mp[a] = 1;
  for (int i = 0; i < n - 1; i++) {
    cin >> a;
    auto itr = mp.find(a);
    if (itr != mp.end()) {
      mp[a] += 1;
    } else {
      mp[a] = 1;
    }
  }
  int q, b, c;
  long long s;
  cin >> q;
  for (int i = 0; i < q; i++) {
    s = 0;
    cin >> b >> c;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
      if (itr->first == b) {
        s += c * itr->second;
      } else {
        s += itr->first * itr->second;
      }
    }
    mp[c] = mp[b];
    mp[b] = 0;
    cout << s << endl;
  }
  return 0;
}
