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