#include <bits/stdc++.h>
using namespace std;
long long int n, vis[100005], color[100005], m, arr[100005];
map<long long int, long long int> mp;
vector<long long int> G[100005], R[100005], com[100005];
stack<long long int> st;
void dfs(long long int u) {
  color[u] = 1;
  for (long long int i = 0; i < (long long int)G[u].size(); i++) {
    long long int v = G[u][i];
    if (color[v] == 1) continue;
    dfs(v);
  }
  st.push(u);
}
void dfs2(long long int u, long long int mark) {
  vis[u] = 1;
  com[mark].push_back(u);
  for (long long int i = 0; i < (long long int)R[u].size(); i++) {
    long long int v = R[u][i];
    if (vis[v] == 1) continue;
    dfs2(v, mark);
  }
}
int main() {
  scanf("%lld", &n);
  for (long long int i = 1; i <= n; i++) scanf("%lld", &arr[i]);
  scanf("%lld", &m);
  for (long long int i = 1; i <= m; i++) {
    long long int a, b;
    scanf("%lld%lld", &a, &b);
    G[a].push_back(b);
    R[b].push_back(a);
  }
  for (long long int i = 1; i <= n; i++) {
    if (color[i] == 1) continue;
    dfs(i);
  }
  long long int mark = 0;
  while (!st.empty()) {
    long long int node = st.top();
    st.pop();
    if (vis[node] == 1) continue;
    mark++;
    dfs2(node, mark);
  }
  long long int way = 1, ans = 0;
  for (long long int i = 1; i <= mark; i++) {
    long long int mn = 1e15, node = 1e15, w = 0;
    for (long long int j = 0; j < (long long int)com[i].size(); j++) {
      long long int v = com[i][j];
      if (arr[v] < mn) {
        mn = arr[v];
        node = v;
      }
    }
    for (long long int j = 0; j < (long long int)com[i].size(); j++) {
      long long int v = com[i][j];
      if (arr[v] == mn) w++;
    }
    ans += mn;
    way = ((way % 1000000007) * (w % 1000000007)) % 1000000007;
  }
  printf("%lld %lld\n", ans, way);
}
