#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int A[n + 1];
  long long int sum = 0;
  unordered_map<int, int> map;
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
    if (map.find(A[i]) != map.end())
      map[A[i]]++;
    else
      map[A[i]] = 1;
    sum += A[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    if (map.find(a) != map.end()) {
      int x = map[a];
      map[b] += map[a];
      map.erase(a);
      sum = sum - (x * a) + (x * b);
      cout << sum << "\n";
    } else {
      cout << sum << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
