#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100, maxp = maxn * 10, maxm = maxn * 14;
int rd() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
struct Edge {
  int a, b, ne;
  long long int l;
} eg[maxm];
struct Node {
  int lt, rt;
} tr[maxp];
int N, Q, S;
int egh[maxp], ect, pct, id[maxn][2], root1, root2;
long long int dis[maxp];
bool flag[maxp];
queue<int> q;
inline void adeg(int a, int b, int l) {
  eg[ect].a = a;
  eg[ect].b = b;
  eg[ect].l = l;
  eg[ect].ne = egh[a];
  egh[a] = ect++;
}
int build1(int l, int r) {
  int p = ++pct;
  if (l == r) {
    id[l][0] = p;
    return p;
  }
  int m = l + r >> 1;
  tr[p].lt = build1(l, m);
  adeg(tr[p].lt, p, 0);
  tr[p].rt = build1(m + 1, r);
  adeg(tr[p].rt, p, 0);
  return p;
}
int build2(int l, int r) {
  int p = ++pct;
  if (l == r) {
    id[l][1] = p;
    adeg(p, id[l][0], 0);
    return p;
  }
  int m = l + r >> 1;
  tr[p].lt = build2(l, m);
  adeg(p, tr[p].lt, 0);
  tr[p].rt = build2(m + 1, r);
  adeg(p, tr[p].rt, 0);
  return p;
}
void cover1(int i, int l, int r, int x, int y, int z, int c) {
  if (x == y) {
    adeg(id[x][0], z, c);
    return;
  }
  if (x <= l && r <= y) {
    adeg(i, z, c);
    return;
  }
  int m = l + r >> 1;
  if (x <= m) cover1(tr[i].lt, l, m, x, y, z, c);
  if (y >= m + 1) cover1(tr[i].rt, m + 1, r, x, y, z, c);
}
void cover2(int i, int l, int r, int x, int y, int z, int c) {
  if (x == y) {
    adeg(z, id[x][1], c);
    return;
  }
  if (x <= l && r <= y) {
    adeg(z, i, c);
    return;
  }
  int m = l + r >> 1;
  if (x <= m) cover2(tr[i].lt, l, m, x, y, z, c);
  if (y >= m + 1) cover2(tr[i].rt, m + 1, r, x, y, z, c);
}
void add(int l1, int r1, int l2, int r2, int c) {
  int m = ++pct;
  cover1(root1, 1, N, l1, r1, m, c);
  cover2(root2, 1, N, l2, r2, m, c);
}
void spfa() {
  while (!q.empty()) q.pop();
  for (int i = 1; i <= pct; i++) {
    dis[i] = 1e14 + 10;
  }
  dis[id[S][0]] = 0;
  q.push(id[S][0]);
  flag[id[S][0]] = 1;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    flag[p] = 0;
    for (int i = egh[p]; i != -1; i = eg[i].ne) {
      if (eg[i].l + dis[p] < dis[eg[i].b]) {
        dis[eg[i].b] = eg[i].l + dis[p];
        if (!flag[eg[i].b]) q.push(eg[i].b);
        flag[eg[i].b] = 1;
      }
    }
  }
}
int main() {
  int i, j, k;
  N = rd(), Q = rd(), S = rd();
  memset(egh, -1, sizeof(egh));
  root1 = build1(1, N);
  root2 = build2(1, N);
  for (i = 1; i <= Q; i++) {
    int a = rd();
    if (a == 1) {
      int b = rd(), c = rd(), d = rd();
      add(b, b, c, c, d);
    } else if (a == 2) {
      int b = rd(), c = rd(), d = rd(), e = rd();
      add(b, b, c, d, e);
    } else {
      int b = rd(), c = rd(), d = rd(), e = rd();
      add(c, d, b, b, e);
    }
  }
  spfa();
  for (i = 1; i <= N; i++) {
    if (dis[id[i][0]] >= 1e14 + 10)
      printf("-1 ");
    else
      printf("%I64d ", dis[id[i][0]] >> 1);
  }
}
