#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using std::swap;
vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
vector<vector<int>> vv;
vector<vector<int>> ww;
int main() {
  int N, Q;
  cin >> N;
  v.resize(100001, 0);
  for (int i = (0); i < (N); i++) {
    int x;
    cin >> x;
    ++v[x];
  }
  cin >> Q;
  vll.resize(Q + 1, 0);
  for (int i = (1); i < (N + 1); i++) {
    vll[0] += v[i] * i;
  }
  for (int i = (1); i < (Q + 1); i++) {
    int x, y;
    cin >> x >> y;
    vll[i] = vll[i - 1] + v[x] * (y - x);
    v[y] += v[x];
    v[x] = 0;
  }
  for (int i = (1); i < (Q + 1); i++) {
    cout << vll[i] << '\n';
  }
  return 0;
}
