#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
using Graph = vector<vector<int>>;
using Edge = map<pair<int, int>, int>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  cout << fixed << setprecision(15);
  long long N;
  cin >> N;
  vector<long long> A(N);
  long long sum = 0;
  map<long long, long long> M;
  for (long long i = 0; i < (long long)(N); ++i) {
    cin >> A[i];
    sum += A[i];
    M[A[i]]++;
  }
  long long Q;
  cin >> Q;
  for (long long i = 0; i < (long long)(Q); ++i) {
    long long b, c;
    cin >> b >> c;
    long long temp;
    sum -= M[b] * b;
    temp = M[b];
    sum += temp * c;
    M[c] += temp;
    cout << sum << endl;
  }
  return 0;
}
