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