#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long MOD = 998244353;
int main(void) {
  int n;
  cin >> n;
  map<int, int> A;
  long long sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    A[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    int B = A[b];
    sum = sum - b * B + c * B;
    A[b] = 0;
    A[c] += B;
    cout << sum << endl;
  }
  return 0;
}
