#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  int sum = 0;
  unordered_map<long long int, long long int> mp;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    mp[v[i]]++;
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int b, c;
    cin >> b >> c;
    mp[c] += mp[b];
    sum -= mp[b] * b;
    sum += mp[b] * c;
    mp[b] = 0;
    cout << sum << "\n";
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
}
