#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long INF = 1e12;
const int MOD = 1e9 + 7;
const unsigned int BIT_FLAG_0 = (1 << 0);
const unsigned int BIT_FLAG_1 = (1 << 1);
const unsigned int BIT_FLAG_2 = (1 << 2);
const unsigned int BIT_FLAG_3 = (1 << 3);
const unsigned int BIT_FLAG_4 = (1 << 4);
const unsigned int BIT_FLAG_5 = (1 << 5);
const unsigned int BIT_FLAG_6 = (1 << 6);
const unsigned int BIT_FLAG_7 = (1 << 7);
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto &vec : df) {
    print(vec);
  }
}
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < long long(n); i++) {
    cin >> A.at(i);
  }
  int sum = accumulate(A.begin(), A.end(), 0);
  map<int, int> counter;
  for (int i = 0; i < long long(n); i++) {
    if (counter.count(A[i])) {
      counter.at(A[i]) += 1;
    } else {
      counter[A[i]] = 1;
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < long long(q); i++) {
    int b, c;
    cin >> b >> c;
    if (counter.count(b)) {
      sum -= b * counter.at(b);
      sum += c * counter.at(b);
      if (counter.count(c)) {
        counter.at(c) += counter.at(b);
      } else {
        counter[c] = counter.at(b);
      }
      counter.erase(b);
      cout << sum << endl;
    } else {
      cout << sum << endl;
    }
  }
}
