#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  vector<long long int> o, e;
  cin >> n;
  for (long long int i = 0; i < 2 * n; i++) {
    long long int a;
    cin >> a;
    if (a % 2 == 0)
      e.push_back(i);
    else
      o.push_back(i);
  }
  if (e.size() % 2 != 0) {
    e.pop_back();
    o.pop_back();
  } else if (o.size() % 2 == 0) {
    e.pop_back();
    e.pop_back();
  }
  for (long long int i = 0; i < e.size(); i = i + 2)
    cout << e[i] + 1 << " " << e[i + 1] + 1 << endl;
  for (long long int i = 0; i < o.size(); i = i + 2)
    cout << o[i] + 1 << " " << o[i + 1] + 1 << endl;
}
void solve1() {
  int n, sum = 0;
  vector<long long int> v(100001, 0);
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    sum += a;
    v[a]++;
  }
  long long int q;
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    long long int x, y;
    cin >> x >> y;
    if (v[x] > 0) {
      sum = sum - x * v[x];
      sum += y * v[x];
      v[y] += v[x];
      v[x] = 0;
    }
    cout << sum << endl;
  }
}
int main() {
  solve1();
  return 0;
}
