#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
vector<long long> x;
vector<long long> graph[100001], rgraph[100001];
vector<bool> visited1(100001, false), visited2(100001, false);
vector<long long> z;
stack<long long> y;
void dfs1(long long k) {
  visited1[k] = true;
  for (auto i : graph[k]) {
    if (!visited1[i]) {
      dfs1(i);
    }
  }
  y.push(k);
}
void dfs2(long long k) {
  visited2[k] = true;
  for (auto i : rgraph[k]) {
    if (!visited2[i]) {
      dfs2(i);
    }
  }
  z.push_back(x[k]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  x.push_back(0);
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    x.push_back(k);
  }
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long p, q;
    cin >> p >> q;
    graph[p].push_back(q);
    rgraph[q].push_back(p);
  }
  for (long long i = 1; i <= n; i++) {
    if (!visited1[i]) {
      dfs1(i);
    }
  }
  long long sum1 = 0;
  vector<long long> counter;
  while (!y.empty()) {
    long long i = y.top();
    y.pop();
    if (!visited2[i]) {
      dfs2(i);
      sort(z.begin(), z.end());
      sum1 += z[0];
      long long count = 0;
      for (long long j = 0; j < z.size(); j++) {
        if (z[j] == z[0]) {
          count++;
        } else {
          break;
        }
      }
      z.clear();
      counter.push_back(count);
    }
  }
  cout << sum1 << " ";
  long long num = 1;
  for (auto i : counter) {
    num *= i;
    num %= mod;
  }
  cout << num;
  return 0;
}
