#include <bits/stdc++.h>
using namespace std;
const long long LongINF = 1e13 + 7;
const int INF = 1e9 + 7;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class Y>
T GCD(T a, Y b) {
  if (a < b) {
    int c = a;
    a = b;
    b = c;
  }
  if (a % b == 0) {
    return b;
  }
  return GCD(b, a % b);
}
template <class T, class Y>
T LCM(T a, Y b) {
  return (a * b) / GCD(a, b);
}
void clear(queue<pair<int, int>>& q) {
  queue<pair<int, int>> empty;
  swap(q, empty);
}
using vi = vector<int>;
using vii = vector<vi>;
int main() {
  int n, q;
  long long sum = 0;
  cin >> n;
  map<int, int> mp;
  for (long long i = (0); i < (n); i++) {
    int a;
    cin >> a;
    sum += a;
    mp[a]++;
  }
  cin >> q;
  for (long long i = (0); i < (q); i++) {
    int b, c;
    cin >> b >> c;
    int x = mp[b];
    mp[b] = 0;
    mp[c] += x;
    sum -= x * b;
    sum += x * c;
    cout << sum << endl;
  }
  return 0;
}
