#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 17);
const int mod = 1e9 + 7;
int add(int a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  return a;
}
int sub(int a, int b) {
  a -= b;
  if (a < 0) a += mod;
  return a;
}
int mul(int a, int b) { return 1ll * a * b % mod; }
int Pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ans;
}
vector<pair<int, int> > g[N];
vector<pair<int, int> > path;
int F[50][N];
int P[50][N];
int v[N];
int tot = 0;
void dfs(int u, int p) {
  if (v[u] > 1) return;
  if (v[u] > 0) {
    for (int j = (int)path.size() - 1; j >= 0; --j) {
      int x = path[j].first;
      int w = path[j].second;
      F[tot][w]++;
      P[tot][w] = 1;
      if (x == u) break;
    }
    ++tot;
    return;
  }
  v[u] = 1;
  for (pair<int, int> e : g[u])
    if (e.first != p) {
      int v = e.first;
      int w = e.second;
      path.emplace_back(u, w);
      dfs(v, u);
      path.pop_back();
    }
  v[u] = 2;
}
void fft(int *f, bool inv) {
  for (int k = 1; k < N; k <<= 1)
    for (int i = 0; i < N; i += k * 2)
      for (int j = 0; j < k; ++j) {
        int x = f[i + j];
        int y = f[i + j + k];
        f[i + j] = add(x, y);
        f[i + j + k] = sub(x, y);
      }
  if (inv) {
    for (int i = 0; i < N; ++i) f[i] = mul(f[i], Pow(N, mod - 2));
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int m;
  cin >> m;
  assert(n + 42 >= m);
  int Sum = 0;
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    int y;
    cin >> y;
    int w;
    cin >> w;
    g[x].emplace_back(y, w);
    g[y].emplace_back(x, w);
    Sum ^= w;
  }
  dfs(1, 0);
  fill(F[tot], F[tot] + N, 1);
  fill(P[tot], P[tot] + N, 1);
  for (int i = 0; i < tot; ++i) {
    fft(F[i], 0);
    fft(P[i], 0);
    for (int j = 0; j < N; ++j)
      F[tot][j] = mul(F[tot][j], F[i][j]), P[tot][j] = mul(P[tot][j], P[i][j]);
  }
  fft(F[tot], 1);
  fft(P[tot], 1);
  int ans = mod;
  int res = 0;
  for (int i = 0; i < N; ++i)
    if (F[tot][i] || P[tot][i]) {
      int nxt = (Sum ^ i);
      if (ans > nxt) {
        ans = nxt;
        res = F[tot][i];
      }
    }
  cout << ans << " ";
  cout << res << endl;
}
