#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
const long long INF = 1e18;
int main() {
  unsigned long long n, sum = 0, q;
  cin >> n;
  vector<unsigned long long> a(100000);
  fill(a.begin(), a.end(), 0);
  for (int i = 0; i < n; i++) {
    int y;
    cin >> y;
    sum += y;
    a.at(y)++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    unsigned long long count = a.at(b);
    a.at(b) = 0;
    sum += (c - b) * count;
    a.at(c) += count;
    cout << sum << endl;
  }
}
