#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int size;
  cin >> size;
  int arr[size];
  for (int i = 0; i < size; i++) {
    cin >> arr[i];
  }
  int op;
  cin >> op;
  while (op--) {
    int B, C;
    cin >> B >> C;
    int sum = 0;
    for (int i = 0; i < size; i++) {
      if (B == arr[i]) {
        arr[i] = C;
      }
      sum = sum + arr[i];
    }
    cout << sum;
    cout << "\n";
  }
  return 0;
}
