#include <bits/stdc++.h>
using namespace std;
map<int, int> vis;
map<int, vector<int>> mapp, trans;
vector<int> ans;
void dfs(int node, stack<int> &st) {
  int i, j, child;
  vis[node] = 1;
  for (i = 0; i < mapp[node].size(); i++) {
    child = mapp[node][i];
    if (vis[child] == 0) {
      dfs(child, st);
    }
  }
  st.push(node);
}
void dfs2(int node) {
  vis[node] = true;
  ans.push_back(node);
  int i, j, child;
  for (i = 0; i < trans[node].size(); i++) {
    child = trans[node][i];
    if (vis[child] == 0) {
      dfs2(child);
    }
  }
}
void solve() {
  int i, j;
  int n, m, u, v, node;
  cin >> n;
  long long int a[n], count, val, temp, perm = 1, sum = 0, mx;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  mx = *max_element(a, a + n);
  mapp.clear();
  trans.clear();
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    mapp[u].push_back(v);
    trans[v].push_back(u);
  }
  stack<int> st;
  vis.clear();
  for (i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      dfs(i, st);
    }
  }
  vis.clear();
  while (!st.empty()) {
    node = st.top();
    st.pop();
    if (vis[node] == 0) {
      ans.clear();
      dfs2(node);
      val = mx + 1;
      count = 0;
      for (j = 0; j < ans.size(); j++) {
        temp = a[ans[j] - 1];
        if (temp < val) {
          val = temp;
          count = 1;
        } else if (temp == val) {
          count++;
        }
      }
      sum += val;
      perm *= count;
      perm %= 1000000007;
    }
  }
  cout << sum << " " << perm << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
