#include <bits/stdc++.h>
using namespace std;
unsigned long long int arraySum(unsigned long long int arr[],
                                unsigned long long int n) {
  unsigned long long int initial_sum = 0;
  return accumulate(arr, arr + n, initial_sum);
}
int main() {
  unsigned long long int n, q, b, c;
  cin >> n;
  unsigned long long int arr[n];
  for (unsigned long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    for (unsigned long long int j = 0; j < n; j++) {
      if (arr[j] == b) {
        arr[j] = c;
      }
    }
    cout << arraySum(arr, n) << "\n";
  }
  return 0;
}
