#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, arr[100006];
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long q;
    cin >> q;
    for (int i = 0; i < q; i++) {
      int b, c;
      cin >> b >> c;
      if (b == c) {
        continue;
      } else {
        long long sum = 0;
        for (int j = 0; j < n; j++) {
          if (b == arr[j]) {
            arr[j] = c;
          }
        }
        for (int j = 0; j < n; j++) {
          sum += (arr[j] % 1000000007);
          sum = sum % 1000000007;
        }
        cout << sum << endl;
      }
    }
  }
  return 0;
}
