#include <bits/stdc++.h>
using namespace std;
const long long OO = (long long)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiou";
template <typename X, typename Y>
bool ckmin(X& a, Y b) {
  return a > b ? a = b, true : false;
}
template <typename X, typename Y>
bool ckmax(X& a, Y b) {
  return a < b ? a = b, true : false;
}
int dcmp(long double d1, long double d2) {
  return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1;
}
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
int conv_2_1(int r, int c, int nCol) { return (nCol * r) + c + 1; }
pair<int, int> conv_1_2(int n, int nCol) {
  int r = n / nCol, c = n % nCol;
  return pair<int, int>(r, c);
}
long long poww(long long num, long long p, long long md = MOD) {
  num %= md;
  long long ret = 1;
  while (p > 0) {
    if (p & 1) ret = (ret * num) % md;
    num = (num * num) % md;
    p >>= 1;
  }
  return ret;
}
void inter(string second) {
  cout << second << endl;
  fflush(stdout);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x;
  cin >> n;
  long long sum = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) cin >> x, sum += x, mp[x]++;
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sum -= mp[a] * a;
    sum += mp[a] * b;
    mp[b] += mp[a];
    mp[a] = 0;
    cout << sum << endl;
  }
  return 0;
}
