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