#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; ++i) cin >> a[i];
  long long int k;
  cin >> k;
  for (long long int i = 0; i < k; ++i) {
    long long int l, m, sum = 0;
    cin >> l >> m;
    for (long long int j = 0; j < n; ++j) {
      if (a[j] == l) a[j] = m;
    }
    for (long long int j = 0; j < n; ++j) sum += a[j];
    cout << sum << "\n";
  }
  return 0;
}
