#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], b[100000], q;
int main() {
  cin >> n;
  long long s = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    s += a[i];
    b[a[i]]++;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    long long y, z;
    cin >> y >> z;
    s = s - b[y] * y + b[y] * z;
    b[z] += b[y];
    b[y] = 0;
    cout << s << endl;
  }
}
