#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
  int N;
  cin >> N;
  int a[100010], s, sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> s;
    a[s]++;
    sum += s;
  }
  int Q;
  cin >> Q;
  int b, c;
  vector<int> r(Q);
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    sum += a[b] * c - a[b] * b;
    a[c] += a[b];
    a[b] = 0;
    r[i] = sum;
  }
  for (int i = 0; i < Q; i++) cout << r[i] << endl;
}
