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