#include <bits/stdc++.h>
using namespace std;
const int K = 1000000007;
bool vis[100005];
int a;
long long mn, cow = 1, sum, cost[100005];
vector<vector<int> > v, k, t;
stack<int> st;
void dfs(int i) {
  vis[i] = 1;
  for (int j = 0; j < v[i].size(); j++)
    if (!vis[v[i][j]]) dfs(v[i][j]);
  st.push(i);
}
void same(int i) {
  vis[i] = 1;
  for (int j = 0; j < k[i].size(); j++)
    if (!vis[k[i][j]]) same(k[i][j]);
  mn = min(mn, cost[i]);
  t[a].push_back(i);
}
int main() {
  int n, m, x, y;
  scanf("%d", &n);
  v.resize(n + 1);
  k.resize(n + 1);
  t.resize(n + 1);
  for (int i = 1; i <= n; i++) scanf("%lld", &cost[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    k[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  memset(vis, 0, sizeof vis);
  while (!st.empty()) {
    mn = 1e18;
    if (!vis[st.top()]) {
      same(st.top());
      sum += mn;
      bool f = false;
      long long c = 1;
      for (int i = 0; i < t[a].size(); i++)
        if (!f && cost[t[a][i]] == mn)
          f = true;
        else if (cost[t[a][i]] == mn && f)
          c++;
      cow = cow % K * (c % K) % K;
      ++a;
    }
    st.pop();
  }
  printf("%lld %lld", sum, cow);
  return 0;
}
