#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v;
  int sum = 0;
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (m.find(a) != m.end()) {
      m[a]++;
    } else
      m[a] = 1;
    sum += a;
    v.push_back(a);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    if (m.find(b) != m.end()) {
      int f = m[b];
      m.erase(b);
      sum = sum - f * b + f * c;
      if (m.find(c) != m.end()) {
        m[c] += f;
      } else
        m[c] = f;
    }
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
