#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int B = 17;
const int MAX = (1 << B) + 10;
int bigMod(int a, int b, int m) {
  if (b == 0) return 1LL;
  int ret = bigMod(a, b / 2, m);
  ret = (ret * 1LL * ret) % m;
  if (b & 1) ret = (ret * 1LL * a) % m;
  return ret;
}
struct fwht {
  int P1[MAX], P2[MAX];
  int MOD, INV;
  fwht() {}
  fwht(int _MOD) {
    MOD = _MOD;
    INV = bigMod(2, MOD - 2, MOD);
  }
  void walsh_transform(int* ar, int n) {
    if (n == 0) return;
    int i, m = n / 2;
    walsh_transform(ar, m);
    walsh_transform(ar + m, m);
    for (i = 0; i < m; i++) {
      int x = ar[i], y = ar[i + m];
      ar[i] = (x + y >= MOD ? x + y - MOD : x + y),
      ar[i + m] = (x - y + MOD >= MOD ? x - y + MOD - MOD : x - y + MOD);
    }
  }
  void inverse_walsh_transform(int* ar, int n) {
    if (n == 0) return;
    int i, m = n / 2;
    inverse_walsh_transform(ar, m);
    inverse_walsh_transform(ar + m, m);
    for (i = 0; i < m; i++) {
      int x = ar[i], y = ar[i + m];
      ar[i] = ((x + y >= MOD ? x + y - MOD : x + y) * 1LL * INV) % MOD;
      ar[i + m] =
          ((x - y + MOD >= MOD ? x - y + MOD - MOD : x - y + MOD) * 1LL * INV) %
          MOD;
    }
  }
  vector<int> convolution(int n, int* A, int* B) {
    for (int i = 0; i < n; i++) P1[i] = A[i];
    for (int i = 0; i < n; i++) P2[i] = B[i];
    walsh_transform(P1, n);
    walsh_transform(P2, n);
    for (int i = 0; i < n; i++) P1[i] = (P1[i] * 1LL * P2[i]) % MOD;
    inverse_walsh_transform(P1, n);
    return vector<int>(P1, P1 + n);
  }
};
struct edges {
  int u, v, w;
} ara[MAX];
vector<int> ed[MAX], isBridge[MAX];
bool vis[MAX];
int st[MAX], low[MAX], Time = 0;
int cnum;
int comp[MAX];
void findBridge(int s, int par) {
  int i, x, ch = 0, j;
  vis[s] = 1;
  Time++;
  st[s] = low[s] = Time;
  for (i = 0; i < ed[s].size(); i++) {
    x = ed[s][i];
    if (!vis[x]) {
      ch++;
      findBridge(x, s);
      low[s] = min(low[s], low[x]);
      if (low[x] > st[s]) {
        isBridge[s][i] = 1;
        j = lower_bound(ed[x].begin(), ed[x].end(), s) - ed[x].begin();
        isBridge[x][j] = 1;
      }
    } else if (par != x)
      low[s] = min(low[s], st[x]);
  }
}
int szComp[MAX];
void dfs(int s) {
  int i, x;
  vis[s] = 1;
  comp[s] = cnum;
  szComp[cnum]++;
  for (i = 0; i < ed[s].size(); i++) {
    if (!isBridge[s][i]) {
      x = ed[s][i];
      if (!vis[x]) dfs(x);
    }
  }
}
int cnt[44][MAX];
vector<int> C;
int RM[MAX];
void processBridge(int n, int m) {
  memset(vis, 0, sizeof(vis));
  Time = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) findBridge(i, -1);
  cnum = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnum++;
      dfs(i);
    }
  }
  for (int i = 1; i <= cnum; i++) {
    if (szComp[i] > 1) {
      RM[i] = C.size();
      C.push_back(i);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (comp[ara[i].u] == comp[ara[i].v]) {
      cnt[RM[comp[ara[i].u]]][ara[i].w]++;
    }
  }
}
int tmp[MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  fwht T1 = fwht(1e9 + 7);
  fwht T2 = fwht(1e9 + 9);
  int n, m, u, v, w;
  cin >> n >> m;
  int tot = 0;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v >> w;
    ed[u].push_back(v);
    ed[v].push_back(u);
    isBridge[u].push_back(0);
    isBridge[v].push_back(0);
    ara[i].u = u;
    ara[i].v = v;
    ara[i].w = w;
    tot ^= w;
  }
  for (int i = 1; i <= n; i++) sort(ed[i].begin(), ed[i].end());
  processBridge(n, m);
  if (C.size() == 0) {
    cout << tot << endl;
  } else if (C.size() == 1) {
    int mn = 1 << (B + 1);
    int ways = 0;
    for (int i = 0; i < (1 << B); i++) {
      if (cnt[0][i]) {
        if (mn > (tot ^ i)) {
          mn = tot ^ i;
          ways = cnt[0][i];
        }
      }
    }
    cout << mn << " " << ways << endl;
  } else {
    vector<int> V1 = T1.convolution(1 << B, cnt[0], cnt[1]);
    vector<int> V2 = T2.convolution(1 << B, cnt[0], cnt[1]);
    for (int i = 2; i < C.size(); i++) {
      for (int j = 0; j < (1 << B); j++) tmp[j] = V1[j];
      V1 = T1.convolution(1 << B, tmp, cnt[i]);
      for (int j = 0; j < (1 << B); j++) tmp[j] = V2[j];
      V2 = T2.convolution(1 << B, tmp, cnt[i]);
    }
    int mn = 1 << (B + 1);
    int ways = 0;
    for (int i = 0; i < (1 << B); i++) {
      if (V1[i] or V2[i]) {
        if (mn > (tot ^ i)) {
          mn = tot ^ i;
          ways = V1[i];
        }
      }
    }
    cout << mn << " " << ways << endl;
  }
  return 0;
}
