#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "Ofast"
int n, m, cost[100005], vis[100005];
vector<int> graph[100005], rev[100005], order, component;
void dfs(int node) {
  vis[node] = 1;
  for (auto to : graph[node])
    if (!vis[to]) dfs(to);
  order.push_back(node);
}
void dfs2(int node) {
  vis[node] = 1;
  component.push_back(node);
  for (auto to : rev[node])
    if (!vis[to]) dfs2(to);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> cost[i];
  cin >> m;
  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v;
    graph[u].push_back(v);
    rev[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  memset(vis, 0, sizeof vis);
  long long mn = 0, count = 1;
  for (int i = order.size() - 1; i >= 0; i--) {
    if (!vis[order[i]]) {
      dfs2(order[i]);
      long long smallest = INT_MAX, freq = 0;
      for (auto x : component) {
        if (cost[x] == smallest)
          freq++;
        else if (cost[x] < smallest) {
          smallest = cost[x];
          freq = 1;
        }
      }
      mn += smallest;
      count = ((count % 1000000007) * (freq % 1000000007)) % 1000000007;
      component.clear();
    }
  }
  cout << mn << ' ' << count << '\n';
  return 0;
}
