#include <bits/stdc++.h>
using namespace std;
vector<pair<int, long long> > road[1000001];
int bac[1000001], n, q, s, a, b, c, mode, cnt;
int id[1000001], to[1000001];
int idd[1000001];
long long d;
long long zdr[1000001];
priority_queue<pair<long long, int> > pq;
void find_to(int now, int l, int r, int fr, long long w, int L, int R) {
  if (r < L || l > R) return;
  if (l >= L && r <= R) {
    road[id[fr]].push_back(make_pair(idd[now], w));
    return;
  }
  find_to(2 * now, l, (l + r) / 2, fr, w, L, R);
  find_to(2 * now + 1, (l + r) / 2 + 1, r, fr, w, L, R);
}
void find_first(int now, int l, int r, int L, int R, int LL, int RR,
                long long w) {
  if (r < L || l > R) return;
  if (l >= L && r <= R) {
    find_to(1, 1, n, now, w, LL, RR);
    return;
  }
  find_first(2 * now, l, (l + r) / 2, L, R, LL, RR, w);
  find_first(2 * now + 1, (l + r) / 2 + 1, r, L, R, LL, RR, w);
}
void make_tree(int now, int l, int r) {
  idd[now] = ++cnt;
  id[now] = ++cnt;
  if (l == r) {
    bac[l] = now;
    return;
  }
  make_tree(2 * now, l, (l + r) >> 1);
  make_tree(2 * now + 1, (l + r) / 2 + 1, r);
  road[idd[now]].push_back(make_pair(idd[2 * now], 0));
  road[idd[now]].push_back(make_pair(idd[2 * now + 1], 0));
  road[id[2 * now]].push_back(make_pair(id[now], 0));
  road[id[2 * now + 1]].push_back(make_pair(id[now], 0));
}
int main() {
  memset(zdr, 0x3f, sizeof(zdr));
  scanf("%d %d %d", &n, &q, &s);
  make_tree(1, 1, n);
  for (int i = 1; i <= n; ++i) {
    road[idd[bac[i]]].push_back(make_pair(id[bac[i]], 0));
  }
  for (int i = 1; i <= q; ++i) {
    scanf("%d", &mode);
    if (mode == 1) {
      scanf("%d %d %lld", &a, &b, &d);
      find_first(1, 1, n, a, a, b, b, d);
    }
    if (mode == 2) {
      scanf("%d %d %d %lld", &a, &b, &c, &d);
      find_first(1, 1, n, a, a, b, c, d);
    }
    if (mode == 3) {
      scanf("%d %d %d %lld", &a, &b, &c, &d);
      find_first(1, 1, n, b, c, a, a, d);
    }
  }
  pq.push(make_pair(0, id[bac[s]]));
  while (pq.size()) {
    int a = pq.top().second;
    long long b = -pq.top().first;
    pq.pop();
    if (zdr[a] != zdr[0]) continue;
    zdr[a] = b;
    for (int i = 0; i < road[a].size(); ++i) {
      pq.push(make_pair(-road[a][i].second - b, road[a][i].first));
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (zdr[id[bac[i]]] == zdr[0])
      cout << -1 << " ";
    else
      cout << zdr[id[bac[i]]] << " ";
  }
}
