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