#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, sum = 0, x, y, a;
  cin >> n;
  int arr[n];
  string s = "";
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cin >> k;
  for (int j = 0; j < k; j++) {
    cin >> x >> y;
    for (int i = 0; i < n; i++) {
      if (arr[i] == x) {
        arr[i] = y;
        sum += arr[i];
      } else
        sum += arr[i];
    }
    cout << sum << endl;
    sum = 0;
  }
}
