#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007, N = 1e5 + 5;
vector<long long> adj[N], rev[N];
long long weight[N];
bool visited[N] = {};
stack<long long> st;
void dfs(long long cur) {
  visited[cur] = true;
  for (long long i = 0; i < adj[cur].size(); i++) {
    long long next = adj[cur][i];
    if (!visited[next]) dfs(next);
  }
  st.push(cur);
}
void dfs2(long long cur, vector<long long>& vec) {
  visited[cur] = true;
  vec.push_back(weight[cur]);
  for (long long i = 0; i < rev[cur].size(); i++) {
    long long next = rev[cur][i];
    if (!visited[next]) dfs2(next, vec);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> weight[i];
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
    rev[y].push_back(x);
  }
  for (long long i = 0; i < n; i++) {
    if (!visited[i]) dfs(i);
  }
  for (long long i = 0; i < n; i++) visited[i] = false;
  vector<vector<long long> > List;
  vector<long long> vec;
  vec.clear();
  while (!st.empty()) {
    long long cur = st.top();
    st.pop();
    if (visited[cur]) continue;
    dfs2(cur, vec);
    List.push_back(vec);
    vec.clear();
  }
  long long minsum = 0, ans = 1;
  for (long long i = 0; i < List.size(); i++) {
    if (List[i].size() == 0) continue;
    sort(List[i].begin(), List[i].end());
    minsum += List[i][0];
    long long least = List[i][0];
    long long ind = -1;
    long long l = 0, h = List[i].size() - 1;
    while (l <= h) {
      long long m = (l + h) / 2;
      if (List[i][m] == least) {
        ind = m;
        l = m + 1;
      } else if (List[i][m] > least)
        h = m - 1;
      else
        l = m + 1;
    }
    ans = ans * (ind + 1);
    ans %= MOD;
  }
  cout << minsum << " " << ans << "\n";
}
