#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (arr[i] == a) {
        arr[i] = b;
      }
    }
    int x = accumulate(arr, arr + n, 0);
    cout << x << endl;
  }
}
