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