#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  std::map<long long, long long> map1;
  long long n, b, c, q, sum = 0;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    map1[arr[i]]++;
    sum += arr[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    long long z = map1[b];
    sum -= z * b;
    sum += c * z;
    cout << sum << "\n";
    map1[c] += z;
  }
  return 0;
}
