#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<long long>>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
void PrintVector(const vector<T>& vec) {
  for (auto val : vec) cout << val << " ";
  cout << endl;
}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  int n;
  cin >> n;
  map<int, int> ma;
  long long tot = 0;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    ma[a]++;
    tot += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    int num = ma[b];
    int diff = c - b;
    tot = tot + (num * diff);
    cout << tot << endl;
    ma[c] += num;
  }
}
