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