#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> v, v1;
  long long n, i, q, s, b, c, a;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    s = 0;
    for (i = 0; i < n; i++) {
      if (v[i] == b) v[i] = c;
      s += v[i];
    }
    v1.push_back(s);
  }
  for (i = 0; i < v1.size(); i++) cout << v1[i] << "\n";
  return 0;
}
