#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int map[100005] = {0};
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    map[temp]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sum -= (map[a] * a);
    sum += (map[a] * b);
    map[b] += map[a];
    map[a] = 0;
    cout << sum << endl;
  }
}
