#include <bits/stdc++.h>
using namespace std;
void Solve() {
  int n;
  cin >> n;
  unordered_map<int, int> m;
  long long total = 0;
  for (int i = 0; i < (n); i++) {
    int temp;
    cin >> temp;
    m[temp]++;
    total += temp;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int temp = 0;
    temp = m[b] * b;
    int count = m[b];
    m[c] += m[b];
    m[b] = 0;
    int temp2 = c * count;
    total = total - temp + temp2;
    cout << total << endl;
  }
}
int main() {
  {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  };
  int t;
  t = 1;
  while (t--) {
    Solve();
  }
  return 0;
}
