#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, q;
  vector<long long> a;
  vector<pair<int, int>> v;
  long long sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    sum += tmp;
    a.push_back(tmp);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    v.push_back(make_pair(b, c));
  }
  vector<long long> sum_log;
  for (auto p : v) {
    int b = p.first;
    int c = p.second;
    size_t cnt = 0;
    for (size_t i = 0; i < a.size(); i++) {
      if (a[i] == b) {
        a[i] = c;
        cnt++;
      }
    }
    int diff = b - c;
    sum = sum - cnt * diff;
    cout << sum << endl;
  }
  return 0;
}
