#include <bits/stdc++.h>
using namespace std;
const int M = 1000005;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int q;
  cin >> q;
  vector<pair<int, int> > b(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b[i].first >> b[i].second;
  }
  vector<int> sum(q);
  for (int j = 0; j < (q); ++j) {
    for (int i = 0; i < (n); ++i) {
      if (a[i] == b[j].first) {
        a[i] = b[j].second;
      }
      sum[j] += a[i];
    }
    cout << sum[j] << endl;
    ;
  }
}
