#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n, m, w[N], group[N], group_cnt[N];
long long group_result[N];
vector<int> graph[N];
vector<int> rev_graph[N];
stack<int> st;
bool visited[N];
void first_dfs(int node) {
  if (visited[node]) return;
  visited[node] = true;
  ;
  for (auto i : graph[node]) {
    if (!visited[i]) {
      first_dfs(i);
    }
  }
  st.push(node);
}
void second_dfs(int node, int gr) {
  if (visited[node]) return;
  visited[node] = true;
  group[node] = gr;
  for (auto i : rev_graph[node]) {
    if (!visited[i]) second_dfs(i, gr);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  cin >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
    rev_graph[v].push_back(u);
  }
  for (int i = 0; i < n; i++) {
    group_result[i] = (1LL << 30);
    group_cnt[i] = 1;
    if (!visited[i]) first_dfs(i);
  }
  memset(visited, false, sizeof(visited));
  int g = 0;
  while (!st.empty()) {
    int curr = st.top();
    st.pop();
    if (visited[curr])
      continue;
    else {
      second_dfs(curr, g);
      g++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (w[i] < group_result[group[i]]) {
      group_result[group[i]] = w[i];
      group_cnt[group[i]] = 1LL;
    } else if (w[i] == group_result[group[i]]) {
      group_cnt[group[i]]++;
    } else {
      continue;
    }
  }
  long long result_sum = 0;
  long long ways = 1;
  for (int i = 0; i < g; i++) {
    result_sum += group_result[i];
    ways *= group_cnt[i];
    ways %= 1000000007;
  }
  cout << result_sum << " " << ways << "\n";
  return 0;
}
