#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int arr[t];
  for (int i = 0; i < t; i++) {
    cin >> arr[i];
  }
  int t1;
  cin >> t1;
  int b, c;
  for (int i = 0; i < t1; i++) {
    cin >> b >> c;
    int sum = 0;
    for (int i = 0; i < t; i++) {
      if (arr[i] == b) {
        arr[i] = c;
      }
      sum = sum + arr[i];
    }
    cout << sum << endl;
  }
}
