#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, q, sum;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  while (q--) {
    sum = 0;
    int b1, c1;
    cin >> b1 >> c1;
    for (int i = 0; i < n; i++) {
      if (a[i] == b1) {
        a[i] = c1;
      }
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}
