#include <bits/stdc++.h>
using namespace std;
long long getSum(const vector<int>& a) {
  int res = 0;
  for (auto t : a) res += t;
  return res;
}
void solve() {
  long long n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.push_back(t);
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == b) {
        a[i] = c;
      }
    }
    cout << getSum(a) << endl;
  }
  return;
}
int main() {
  solve();
  return 0;
}
