#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a;
  long long sum = 0;
  int mp[111111] = {0};
  for (int i = 0; i < n; ++i) {
    int val;
    cin >> val;
    ++mp[val];
    sum += val;
    a.push_back(val);
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    long long ans = sum - b * mp[b];
    ans += c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    sum = ans;
    cout << ans << '\n';
  }
}
