#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> var;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    var.push_back(a);
  }
  int q;
  cin >> q;
  while (q) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < var.size(); i++) {
      if (var[i] == b) var[i] = c;
    }
    cout << accumulate(var.begin(), var.end(), 0);
    q--;
  }
}
