#include<iostream>
#include<cstdio>
using namespace std;
const int N=1005;
int h,w,A,B;
int a[N][N];
int main()
{
	scanf("%d%d%d%d",&h,&w,&A,&B);
	for(int i=1;i<=B;i++)
		for(int j=1;j<=A;j++)
			a[i][j]=1;
	for(int i=B+1;i<=h;i++)
		for(int j=A+1;j<=w;j++)
			a[i][j]=1;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
			printf("%d",a[i][j]);
		printf("\n");
	}
	return 0;
}
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>

using namespace std;

const int Inf = 10000 * 100000 + 100;

int main(){
  int V,E,R;
  cin >> V >> E >> R;
  vector<int> s(E),t(E),d(E);
  vector<vector<int> > edge(V);
  for(int i = 0; i < E; i++){
    cin >> s[i] >> t[i] >> d[i];
    edge[s[i]].push_back(i);
  }
  vector<int> cost(V, Inf);
  cost[R] = 0;

  // < ?§??????????????????¢, ?????????id >
  priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > q;
  q.push({0, R});

  // ????????????????????????
  vector<bool> fin(V, false);

  // vector<vector<int> > edge(V);
  // for(int i = 0; i < V; i++){
  //   edge[i] = {};
  //   // ?????? i ?????????????????????????????????
  //   for(int j = 0; j < E; j++){
  //     if(s[j] == i) edge[i].push_back(j);
  //   }
  // }


  while(!q.empty()){
    // ?¢?????????????????????? u ??¨??????
    auto npair = q.top();
    int nd = npair.first, nu = npair.second;
    // cout << nd << " : " << nu << endl;

    q.pop();
    if(fin[nu]) continue; // ?¢??????????????????????
    fin[nu] = true;
    cost[nu] = nd;
    for(auto i : edge[nu]){
      // u ????§??????§?¢????????????§???????????????????????????????????????
      if(!fin[t[i]]){
        // ????????? v ??¨??????.
        int nv = t[i];
        // ????????§?????????????????????
        if(cost[nu] + d[i] < cost[nv]){
          cost[nv] = cost[nu] + d[i];
          q.push({cost[nv], nv});
        }
      }
    }
  }

  for(int i = 0; i < V; i++){
    if(cost[i] == Inf)
      cout << "INF";
    else
      cout << cost[i];

    cout << endl;
  }
}