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