#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long inf = 1e18;
long long m_inf = INT_MIN;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::cout.unsetf(std::ios::fixed);
  std::cout.precision(9);
  long long t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> arr(n);
    for (long long i = 0; i < n; i++) cin >> arr[i];
    map<long long, long long> m;
    long long sum = accumulate(arr.begin(), arr.end(), 0);
    for (long long i = 0; i < n; i++) m[arr[i]]++;
    long long q;
    cin >> q;
    while (q--) {
      long long b, c;
      cin >> b >> c;
      if (m.find(b) == m.end()) {
        cout << sum << '\n';
        continue;
      }
      long long cnt = m[b];
      m.erase(b);
      m[c] += cnt;
      sum = sum - (cnt * b) + (cnt * c);
      cout << sum << '\n';
    }
  }
}
