#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7, inf = 0x7f7f7f7f;
int n, m, tot, cnt;
int w[maxn], tp[maxn], belong[maxn], mn[maxn], p[maxn];
vector<int> G[maxn], RG[maxn];
bool vis[maxn];
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!vis[v]) dfs(v);
  }
  tp[++tot] = u;
}
void rdfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < RG[u].size(); i++) {
    int v = RG[u][i];
    if (!vis[v]) rdfs(v);
  }
  belong[u] = cnt;
  if (w[u] < mn[cnt])
    mn[cnt] = w[u], p[cnt] = 1;
  else if (w[u] == mn[cnt])
    p[cnt]++;
}
void scc() {
  memset(vis, 0, sizeof(vis));
  for (int i = tot; i >= 1; i--)
    if (!vis[tp[i]]) cnt++, rdfs(tp[i]);
}
void solve() {
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  memset(mn, inf, sizeof(mn));
  scc();
  long long ans = 0, res = 1;
  for (int i = 1; i <= cnt; i++) {
    ans += mn[i];
    res *= p[i] % mod;
    res %= mod;
  }
  printf("%lld %lld", ans, res);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  scanf("%d", &m);
  int u, v;
  while (m--) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    RG[v].push_back(u);
  }
  solve();
  return 0;
}
