#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  int ans = 0;
  unordered_map<int, int> count_map;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    ans += temp;
    if (count_map.find(temp) == count_map.end())
      count_map[temp] = 1;
    else
      count_map[temp]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    ans += (b - a) * count_map[a];
    if (count_map.find(b) == count_map.end())
      count_map[b] = count_map[a];
    else
      count_map[b] += count_map[a];
    count_map[a] = 0;
    cout << ans << endl;
  }
  return 0;
}
