#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  cin >> n;
  long ar[n];
  for (long i = 0; i < n; i++) {
    cin >> ar[i];
  }
  long q;
  sort(ar, ar + n);
  while (q-- > 0) {
    long x, y;
    cin >> x >> y;
    long sum = 0;
    for (long i = 0; i < n; i++) {
      if (ar[i] == x) {
        ar[i] = y;
      }
      sum += ar[i];
    }
    cout << sum << endl;
  }
  return 0;
}
