#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

struct Ad{ll x, y, r, num;};
struct Recang{
    ll x1, y1, x2, y2;
    ll size(){
        return abs(x2-x1)*abs(y2-y1);
    }
};

const int MAX=9999;
int n;
Ad ads[300];
Recang ans[300];

bool overlap(Recang a, Recang b){
    return max(a.x1,b.x1)<min(a.x2,b.x2)&&max(a.y1,b.y1)<min(a.y2,b.y2);
}

bool check(Recang a, int k){
    REP(i,n){
        if(i==k)
            continue;
        if(overlap(a,ans[i]))
            return 1;
    }
    return 0;
}

void solve(){
    cin >> n;
    int x, y, r;
    REP(i,n){
        cin >> x >> y >> r;
        ads[i]=Ad{x,y,r,i};
    }
    sort(ads,ads+n,[](const Ad& a, const Ad& b){return a.r<b.r;});
    REP(i,n){
        Ad ad=ads[i];
        ans[ad.num]={ad.x,ad.y,ad.x+1,ad.y+1};
    }
    REP(i,n){
        Ad ad=ads[i];
        Recang tmpr={ad.x,ad.y,ad.x+1,ad.y+1};
        while(1){
            bool ok=0;
            tmpr.x1--;
            if(tmpr.x1<0||check(tmpr,ad.num)) tmpr.x1++;
            else ok=1;
            if(tmpr.size()>ad.r) break;
            tmpr.y1--;
            if(tmpr.y1<0||check(tmpr,ad.num)) tmpr.y1++;
            else ok=1;
            if(tmpr.size()>ad.r) break;
            tmpr.x2++;
            if(tmpr.x2>MAX||check(tmpr,ad.num)) tmpr.x2--;
            else ok=1;
            if(tmpr.size()>ad.r) break;
            tmpr.y2++;
            if(tmpr.y2>MAX||check(tmpr,ad.num)) tmpr.y2--;
            else ok=1;
            if(tmpr.size()>ad.r) break;
            if(!ok) break;
        }
        ans[ad.num]=tmpr;
    }
    REP(i,n){
        Recang tmpr=ans[i];
        cout << tmpr.x1 << " ";
        cout << tmpr.y1 << " ";
        cout << tmpr.x2 << " ";
        cout << tmpr.y2 << endl;
    }
}

int main(){
    solve();
    return 0;
}
/**
 *   author:  Niloy_Das
 *   created: 2021-06-06 18:19:58
**/

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define firstio() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fo(i,k,n) for ( i = k; i < n; i++)
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " ";print(x);cerr<<endl;
#else
#define debug(x)
#endif

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

void print(int x){cerr << x;}
void print(ll x){cerr << x;}
void print(double x){cerr << x;}
void print(char x){cerr << x;}
void print(string x){cerr << x;}

template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T,class V> void print(map <T,V> v) {cerr << endl <<  "[ \n"; for (auto i=v.begin();i!=v.end();i++) {print(i->F); cerr << " "; print(i->S); cerr<<endl;} cerr << "]";}

int n,m;

int bfs(vector<vector<int>> &graph,int source){
    queue<int>q;
    vector<bool>visit(n+1,false);
    q.push(source);
    visit[source] = true;
    int sum = 0;
    while (!q.empty())
    {
        int k = q.front();
        q.pop();
        for(auto it:graph[k]){
            if(!visit[it]){
                sum++;
                q.push(it);
                visit[it] = true;
            }
        }
    }

    
    return sum;
}


int main()
{
    firstio()
    #ifndef ONLINE_JUDGE
       freopen("Error.txt","w",stderr);
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif

    int t = 1,i;
    // cin >> t;
    while(t--){
         cin >> n >> m;
         vector<vector<int>> graph(n+1);
         fo(i,0,m){
             int a,b;
             cin >> a >> b;
             graph[a].push_back(b);
         }
         int sum=n;
         fo(i,1,n+1){
             sum+=bfs(graph,i);
         }
         cout << sum << "\n";
    }
    return 0;
}