#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  ll ans(0);
  for (int i = 0; i < (n); ++i) {
    int buf;
    cin >> buf;
    m[buf]++;
    ans += buf;
  }
  int q;
  cin >> q;
  vector<int> qans(q);
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    int cnt = m[b];
    ans -= b * cnt;
    ans += c * cnt;
    qans[i] = ans;
    m[b] -= cnt;
    m[c] += cnt;
  }
  for (int i = 0; i < (q); ++i) {
    cout << qans[i] << endl;
  }
  return 0;
}
