#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr;
  for (int i{0}; i < n; i++) {
    int a;
    cin >> a;
    arr.push_back(a);
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    long long int sum = 0;
    for (int i{0}; i < arr.size(); i++) {
      if (arr.at(i) == b) {
        arr.at(i) = c;
      }
    }
    for (int i{0}; i < arr.size(); i++) {
      sum = sum + arr.at(i);
    }
    cout << sum << endl;
  }
}
