#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long n, t, p, p1, p2, q = 0, c;
  cin >> n;
  vector<unsigned long long> v;
  for (unsigned long long i = 0; i < n; i++) {
    cin >> p;
    v.push_back(p);
    q = q + p;
  }
  cin >> t;
  for (unsigned long long i = 0; i < t; i++) {
    cin >> p1 >> p2;
    c = count(v.begin(), v.end(), p1);
    replace(v.begin(), v.end(), p1, p2);
    q = (q - (c * p1)) + (c * p2);
    cout << q << endl;
  }
  return 0;
}
