#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n, sum = 0;
  int a[100000 + 5], c[100000 + 5];
  cin >> n;
  for (int i = 0; i <= n; i++) c[i] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    c[a[i]] += 1;
  }
  int q;
  cin >> q;
  int b[100000 + 5];
  for (int i = 1; i <= q; i++) {
    int x, y;
    cin >> x >> y;
    sum += c[x] * (y - x);
    b[i] = sum;
    c[y] += c[x], c[x] = 0;
  }
  for (int i = 1; i <= q; i++) cout << b[i] << endl;
  return 0;
}
