#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  vector<pair<int, int>> b(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i].first >> b[i].second;
  }
  for (int i = 0; i < q; i++) {
    long long sum = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i].first) {
        a[j] = b[i].second;
      }
      sum += a[j];
    }
    cout << sum << endl;
  }
  return 0;
}
