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