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