#include <bits/stdc++.h>
using namespace std;
vector<int> v[100004], vop[100005];
stack<int> st;
int visited[100005];
long long min1 = 1234567897, ct = 0;
void dfs(int cur) {
  visited[cur] = 1;
  for (int i = 0; i < v[cur].size(); i++) {
    if (!visited[v[cur][i]]) {
      dfs(v[cur][i]);
    }
  }
  st.push(cur);
}
void gettranspose() {
  for (int i = 1; i <= 100000; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      vop[v[i][j]].push_back(i);
    }
  }
}
void dfs1(int cur, int a[]) {
  visited[cur] = 1;
  if (min1 > (long long)a[cur]) {
    min1 = (long long)a[cur];
    ct = 1LL;
  } else if (min1 == (long long)a[cur]) {
    ct = ct + 1LL;
  }
  for (int i = 0; i < vop[cur].size(); i++) {
    if (!visited[vop[cur][i]]) {
      dfs1(vop[cur][i], a);
    }
  }
}
int main() {
  int n;
  cin >> n;
  int a[n + 1], i;
  for (i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  int m;
  cin >> m;
  for (i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
  }
  memset(visited, 0, sizeof(visited));
  for (i = 1; i <= n; i++) {
    if (!visited[i]) {
      dfs(i);
    }
  }
  gettranspose();
  memset(visited, 0, sizeof(visited));
  long long ans = 1, ans1 = 0;
  while (!st.empty()) {
    int t = st.top();
    min1 = 1234567897;
    ct = 1;
    st.pop();
    if (!visited[t]) {
      dfs1(t, a);
      ans = ans * ct;
      ans = ans % 1000000007LL;
      ans1 = ans1 + min1;
    }
  }
  printf("%lld %lld", ans1, ans);
  return 0;
}
