#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  int n, q;
  cin >> n;
  vector<int> m(105, 0);
  long long total = 0;
  for (int i = 0; i < (n); i++) {
    int a;
    cin >> a;
    m[a] += 1;
    total += a;
  }
  cin >> q;
  int b;
  int c;
  for (int i = 0; i < (q); i++) {
    cin >> b >> c;
    int s = c - b;
    total = total + (m[b] * s);
    cout << total << "\n";
    m[c] += m[b];
    m[b] = 0;
  }
  cout << endl;
  return 0;
}
