#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long MOD = 1000000007;
int n, m, a1 = 1, a2, c[500005];
long long cost;
vector<int> g[500005], r[500005], comp[500005];
bitset<500005> w;
stack<int> s;
void dfs1(int v) {
  w[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    if (!w[g[v][i]]) dfs1(g[v][i]);
  }
  s.push(v);
}
void dfs2(int v) {
  comp[a2].push_back(v);
  w[v] = 1;
  for (int i = 0; i < r[v].size(); i++) {
    if (!w[r[v][i]]) dfs2(r[v][i]);
  }
}
void get() {
  for (int i = 1; i <= n; i++) {
    if (!w[i]) dfs1(i);
  }
  w.reset();
  while (s.size()) {
    int v = s.top();
    s.pop();
    if (!w[v]) {
      dfs2(v);
      a2++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.precision(30);
  cerr.precision(7);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    r[v].push_back(u);
  }
  get();
  for (int i = 0; i < a2; i++) {
    int cur = 0, mn = 1000000000;
    for (int j = 0; j < comp[i].size(); j++) {
      if (c[comp[i][j]] < mn) {
        cur = 1;
        mn = c[comp[i][j]];
      } else if (c[comp[i][j]] == mn)
        cur++;
    }
    cost += mn;
    a1 = (((long long)a1 % MOD) * ((long long)cur % MOD)) % MOD;
  }
  cout << cost << " " << a1;
  return 0;
}
