#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using vch = vector<char>;
using vll = vector<ll>;
using vpii = vector<pii>;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
const ll M = 1e9 + 7;
const int N = 1e6 + 7;
int main() {
  int n, res = 0;
  cin >> n;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    res += a[i];
    mp[a[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    res += (c - b) * mp[b];
    mp[c] += mp[b];
    cout << res << endl;
  }
}
