#include <bits/stdc++.h>
const double EPS = 1e-24;
const long long int MOD = 1000000007ll;
const double PI = 3.14159265359;
int INF = 2147483645;
template <class T>
T Max2(T a, T b) {
  return a < b ? b : a;
}
template <class T>
T Min2(T a, T b) {
  return a < b ? a : b;
}
template <class T>
T Max3(T a, T b, T c) {
  return Max2(Max2(a, b), c);
}
template <class T>
T Min3(T a, T b, T c) {
  return Min2(Min2(a, b), c);
}
template <class T>
T Max4(T a, T b, T c, T d) {
  return Max2(Max2(a, b), Max2(c, d));
}
template <class T>
T Min4(T a, T b, T c, T d) {
  return Min2(Min2(a, b), Max2(c, d));
}
template <class T>
void Swap(T& a, T& b) {
  T temp;
  temp = a;
  a = b;
  b = temp;
}
using namespace std;
long long int N, M;
long long int c[100010];
vector<long long int> G[100010], Gt[100010];
bool vis[100010], vis1[100010];
stack<long long int> scc;
long long int anscost;
long long int answays = 1;
long long int m, cost, ways;
vector<long long int> cv;
void dfs(long long int u) {
  vis[u] = true;
  for (long long int i = 0; i < G[u].size(); i++) {
    long long int v = G[u][i];
    if (!vis[v]) dfs(v);
  }
  scc.push(u);
}
void dfs2(long long int u) {
  if (c[u] < c[m]) m = u;
  cv.push_back(c[u]);
  vis[u] = true;
  for (long long int i = 0; i < Gt[u].size(); i++) {
    long long int v = Gt[u][i];
    if (!vis[v]) dfs2(v);
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> N;
  for (long long int i = 1; i <= N; i++) cin >> c[i];
  cin >> M;
  for (long long int i = 1; i <= M; i++) {
    long long int u, v;
    cin >> u >> v;
    G[u].push_back(v);
    Gt[v].push_back(u);
  }
  for (long long int i = 1; i <= N; i++)
    if (!vis[i]) dfs(i);
  for (long long int i = 1; i <= N; i++) vis[i] = false;
  while (!scc.empty()) {
    long long int u = scc.top();
    if (!vis[u]) {
      m = u;
      cv.clear();
      dfs2(u);
      cost = c[m];
      ways = 0;
      for (int i = 0; i < cv.size(); i++)
        if (cv[i] == cost) ways++;
      anscost += cost;
      answays = (answays * ways) % MOD;
    }
    scc.pop();
  }
  cout << anscost << " " << answays;
  return 0;
}
