loop {
    s = gets.chomp
    break if s == "#"
    a = s.gsub("north", "N").gsub("west", "W").reverse

    ans = Rational(a[0] == "N" ? 0 : 90, 1)
    (1...a.size).each do |i|
        if a[i] == 'N'
            ans -= Rational(90, 2 ** i)
        else
            ans += Rational(90, 2 ** i)
        end
    end
    puts ans.denominator == 1 ? ans.numerator : ans
}
