#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int MOD = 1000000007;
const long long INF = 1e18;
const int MX = 100001;
string get_str() {
  string temp;
  cin >> temp;
  return temp;
}
int get_int() {
  int temp;
  cin >> temp;
  return temp;
}
long long n, a[100000], q;
int main() {
  cin >> n;
  long long s = 0;
  for (int i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    s += x;
    a[x]++;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    long long b, c;
    cin >> b >> c;
    s = s - (a[b] * b) + (a[b] * c);
    a[c] += a[b];
    a[b] = 0;
    cout << s << endl;
  }
}
