def f(dirs)
    if dirs.size == 1
        dirs[0][0] == ?n ? Rational(0) : Rational(90)
    else
        d = (dirs[0][0] == ?n ? Rational(-90) : Rational(90))
        f(dirs[1..-1]) + d / 2 ** (dirs.size-1) 
    end
end 

loop {
    s = gets.chomp
    break if s == ?#
    r = f(s.scan(/north|west/))
    puts r.to_i == r ? r.to_i : r
}