#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const ll INF = 1e+9;
const ld PI = acos((long double)(-1));
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q, sum = 0;
  cin >> n;
  vector<int> a(n + 10, 0);
  for (int(i) = (0); (i) < (n); (++i)) {
    int e;
    cin >> e;
    a[e]++;
    sum += e;
  }
  cin >> q;
  for (int(i) = (0); (i) < (q); (++i)) {
    int b, c;
    cin >> b >> c;
    sum -= a[b] * b;
    sum -= a[c] * c;
    a[c] += a[b];
    a[b] = 0;
    sum += a[c] * c;
    cout << (sum) << endl;
    ;
  }
}
