#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1e9;
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  map<long long, long long> mp;
  for (int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int j = 0; j < q; ++j) {
    long long b, c;
    cin >> b >> c;
    long long cnt = mp[b];
    sum -= cnt * b;
    mp[c] += cnt;
    sum += cnt * c;
    cout << sum << endl;
  }
  return 0;
}
