#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int q;
  cin >> q;
  vector<int> a(q), b(q);
  vector<int> ans;
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i];
    int cur = 0;
    for (int j = 0; j < n; j++) {
      if (arr[j] == a[i]) arr[j] = b[i];
      cur += arr[j];
    }
    ans.push_back(cur);
  }
  for (auto& ele : ans) {
    cout << ele << endl;
  }
  return 0;
}
