#!/usr/bin/env tclsh9.0
namespace import ::tcl::mathop::*

set rows 103
set cols 101
set turns 100
if {[llength $argv] == 2} {lassign $argv rows cols}
if {[llength $argv] == 3} {lassign $argv rows cols turns}

proc input {} {
    global rows cols turns ends
    set ends [list]
    set re {p=(-?\d+),(-?\d+) v=(-?\d+),(-?\d+)}
    while {[gets stdin line] >= 0} {
        if {$line eq ""} continue
        if {! [regexp $re $line -> pc pr vc vr]} continue

        set r [expr {($pr + $vr*$turns) % $rows}]
        set c [expr {($pc + $vc*$turns) % $cols}]
        lappend ends [list $r $c]
    }
    # puts "#ends = [llength $ends]"
}

proc count {} {
    global rows cols ends
    set nw 0; set ne 0; set sw 0; set se 0
    set rm [expr {($rows - 1) / 2}]
    set cm [expr {($cols - 1) / 2}]

    foreach rc $ends {
        lassign $rc r c
        if {$r == $rm || $c == $cm} continue
        if {$r < $rm && $c < $cm} {incr nw; continue}
        if {$r < $rm && $c > $cm} {incr ne; continue}
        if {$r > $rm && $c < $cm} {incr sw; continue}
        incr se
    }

    # puts "nw=$nw ne=$ne sw=$sw se=$se"
    puts [* $nw $ne $sw $se]
}

input
count