#include <bits/stdc++.h>
using namespace std;
long long int sum(long long int arr[], long long int n) {
  long long int s = 0;
  for (long long int i = 0; i < n; i++) s += arr[i];
  return s;
}
int main() {
  long long int n;
  cin >> n;
  long long int arr[100000];
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  long long int q;
  cin >> q;
  while (q--) {
    long long int a, b;
    cin >> a >> b;
    long long int old_val = a;
    long long int new_val = b;
    replace(arr, arr + n, old_val, new_val);
    cout << sum(arr, n) << "\n";
  }
  return 0;
}
