#include <bits/stdc++.h>
using namespace std;
long long int sum(long long int* array, long long int size) {
  long long int sum = 0;
  for (long long int i = 0; i < size; i++) {
    sum += array[i];
  }
  return sum;
}
int main() {
  long long int n, q, b, c;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    cin >> b >> c;
    for (long long int j = 0; j < n; j++) {
      if (a[j] == b) a[j] = c;
    }
    cout << sum(a, n) << "\n";
  }
}
