#include <bits/stdc++.h>
const int MOD = 1000000007;
using namespace std;
int a[106];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> v(n);
  map<long long, long long> mp;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
    sum += v[i];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    long long z = mp[a];
    mp[b] += z;
    long long ans = (sum - a * z + b * z);
    sum = ans;
    cout << ans << "\n";
  }
}
