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