#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, sum = 0;
  cin >> n;
  vector<int> x(100010);
  for (int i = 1; i < n + 1; i++) {
    int a;
    cin >> a;
    sum += a;
    x.at(a)++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum = sum + (c - b) * x.at(b);
    cout << sum << endl;
    x.at(c) = x.at(c) + x.at(b);
    x.at(b) = 0;
  }
}
