#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<int, int>;
const LL MX = 100005;
int main() {
  int n;
  cin >> n;
  vector<int> a(MX);
  int ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int d;
    cin >> d;
    a[d]++;
    ans += d;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    ans += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << ans << endl;
  }
  return 0;
}
