#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20;
const int MOD = 1e9 + 7;
priority_queue<pair<int, int> > pq;
vector<pair<int, int> > vp;
map<int, int> mp, mpp;
vector<int> v;
int visit[N];
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << "  ";
  __f(comma + 1, args...);
}
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  long long int sum = 0;
  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int yo = mp[a];
    sum -= a * yo;
    sum += b * yo;
    mp[b] += yo;
    mp[a] = 0;
    cout << sum << endl;
  }
}
