#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vec = vector<T>;
int main() {
  int n, q;
  cin >> n;
  vec<unsigned long long> a(n);
  unordered_map<unsigned long long, unsigned long long> kosuu;
  for (int i = 0; i < n; i++) {
    unsigned long long hoge;
    cin >> hoge;
    a[i] = hoge;
    kosuu[hoge]++;
  }
  unsigned long long sum = accumulate(a.begin(), a.end(), 0);
  cin >> q;
  while (q > 0) {
    q--;
    unsigned long long b, c;
    cin >> b >> c;
    if (kosuu.find(b) != kosuu.end()) {
      sum += kosuu[b] * (c - b);
      kosuu[c] += kosuu[b];
      kosuu[b] = 0;
      cout << sum << endl;
    } else {
      cout << sum << endl;
    }
  }
}
