#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int sum = 0;
  unordered_map<int, int> mp1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    mp1[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum += c * mp1[b];
    sum -= b * mp1[b];
    mp1[c] += mp1[b];
    mp1[b] = 0;
    cout << sum << "\n";
  }
}
