#include <bits/stdc++.h>
using namespace std;
int n, m, f[200001];
vector<tuple<int, int, int>> e[200001];
struct edge {
  int i, j, w, dir;
  void read(int id) {
    scanf("%d%d%d", &i, &j, &w);
    f[i] += w;
    f[j] += w;
    e[i].emplace_back(j, w, id);
    e[j].emplace_back(i, w, id);
  }
  void set(int a) { dir = a == i; }
} er[200001];
queue<int> q;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) er[i].read(i);
  for (int i = 0; i < n; ++i) f[i] >>= 1;
  f[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    for (auto&& x : p[e]) {
      if (!(f[get<0>(x)] -= get<1>(x)) && get<0>(x) != 1) q.push(get<0>(x));
      er[get<2>(x)].set(p);
    }
  }
  for (int i = 0; i < m; ++i) printf("%d\n", i[er].dir);
}
