#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int gcd_func(int a, int b) { return b ? gcd_func(b, a % b) : a; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int mp[100010];
  long long sm = 0;
  for (int i = 0; i < n; i++) {
    int ipt;
    cin >> ipt;
    mp[ipt]++;
    sm += ipt;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    long long diff = c - b;
    int occ = mp[b];
    mp[b] = 0;
    mp[c] += occ;
    sm += occ * diff;
    cout << sm << endl;
  }
}
