#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < (int(vec.size())); i++)
    os << vec[i] << (i + 1 == int(vec.size()) ? "" : ", ");
  return os;
}
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head << ((sizeof...(tail) != 0) ? " " : "");
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T>& vec) {
  for (auto& a : vec) {
    cout << a << ((&a != &vec.back()) ? " " : "");
  }
  cout << endl;
}
template <class T>
void print(vector<vector<T>>& df) {
  for (auto& vec : df) {
    print(vec);
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  int q;
  cin >> q;
  map<int, int> mp;
  for (int i = 0; i < (n); i++) mp[a[i]]++;
  ll total = accumulate(a.begin(), a.end(), 0ll);
  for (int i = 0; i < (q); i++) {
    int fr, to;
    cin >> fr >> to;
    total -= fr * mp[fr];
    mp[to] += mp[fr];
    total += to * mp[fr];
    mp[fr] = 0;
    cout << total << endl;
  }
}
