#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int a[100005];
bool vis[100005];
int mn[100005], p[100005], dp[100005];
vector<int> g[100005], gr[100005];
stack<int> st;
int root(int a) {
  while (a != p[a]) {
    p[a] = p[p[a]];
    a = p[a];
  }
  return a;
}
void merge(int a, int b) {
  a = root(a);
  b = root(b);
  if (mn[a] == mn[b]) {
    dp[b] += dp[a];
  } else if (mn[a] < mn[b]) {
    mn[b] = mn[a];
    dp[b] = dp[a];
  }
  p[a] = b;
}
void dfs1(int u) {
  vis[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (vis[v]) continue;
    dfs1(v);
  }
  st.push(u);
}
void dfs2(int u, int p) {
  vis[u] = 1;
  if (p != 0) merge(u, p);
  for (int i = 0; i < gr[u].size(); i++) {
    int v = gr[u][i];
    if (vis[v]) continue;
    dfs2(v, u);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), p[i] = i, mn[i] = a[i], dp[i] = 1;
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    gr[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    dfs1(i);
  }
  memset(vis, 0, sizeof(vis));
  while (!st.empty()) {
    int u = st.top();
    st.pop();
    if (vis[u]) continue;
    dfs2(u, 0);
  }
  memset(vis, 0, sizeof(vis));
  long long ans1 = 0, ans2 = 1;
  for (int i = 1; i <= n; i++) {
    int r = root(i);
    if (vis[r]) continue;
    vis[r] = 1;
    ans1 += mn[r];
    ans2 = (ans2 * dp[r]) % mod;
  }
  printf("%lld %lld\n", ans1, ans2);
}
