#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<int> v;
  long long arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    v.push_back(arr[i]);
  }
  int x;
  long long sum = 0;
  cin >> x;
  for (int i = 1; i <= x; i++) {
    int a, b;
    cin >> a >> b;
    if (binary_search(v.begin(), v.end(), a)) {
      sum = 0;
      for (int i = 0; i < n; i++) {
        if (arr[i] == a) {
          arr[i] = b;
        }
        sum += arr[i];
      }
      cout << sum << endl;
    } else
      cout << sum << endl;
  }
  return 0;
}
