#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < (int)((int)(v).size()); j++) i >> v[j];
  return i;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  ;
  mii a;
  int sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    int k;
    cin >> k;
    ;
    a[k]++;
    sum += k;
  }
  int q;
  cin >> q;
  ;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    sum += a[b] * (c - b);
    a[c] += a[b];
    a[b] = 0;
    cout << (sum) << endl;
    ;
  }
}
