#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i += 1) {
    cin >> a;
    v.push_back(a);
  }
  int t;
  cin >> t;
  while (t--) {
    int l, r;
    cin >> l >> r;
    long long sum = 0;
    for (int i = 0; i < v.size(); i += 1) {
      if (v[i] == l) v[i] = r;
      sum = sum + v[i];
    }
    cout << sum << endl;
  }
  return 0;
}
