#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  map<int, int> m;
  for (long long i = (0); i < (n); i++) {
    int a;
    cin >> a;
    m[a]++;
  }
  int sum = 0;
  for (auto it : m) sum += it.first * it.second;
  int q;
  cin >> q;
  for (long long i = (0); i < (q); i++) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * m[b];
    m[c] += m[b];
    m[b] = 0;
    cout << sum << endl;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
