Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Problem H:
DisconnectedGame

Taro と Hanako がゲームをしている.

最初に, 非連結な無向グラフ(二重辺や self loop を含まない) が与えられる. Taro と Hanako は交互に操作を行う. 操作では, 辺で直接つながれていない異なる2 頂点を選び, その間に辺を加える. グラフを連結にしたほうが負けである.

グラフには $V$ 個の頂点がある. $V \times V$ の行列が与えられる. 行列の $(i, j)$-成分が'Y' であるとき $i$ と $j$ の間には辺があり, 'N' であるときは辺が無い.

両者が最善に操作をしたとき, どちらが勝つかを出力せよ.

Constraints

$V$ will be between 2 and 1,000, inclusive.

$a_{i,i}$ will be 'N'.

$a_{i,j}$ will be 'Y' or 'N'.

$a_{i,j}$ will be equal to $a_{j,i}$.

The graph will not be connected.

Input

入力は以下の形式で与えられる:

$V$

$a_{1,1}$ ... $a_{1,V}$

...

$a_{V,1}$ ... $a_{V,V}$

Output

Taro が勝つ場合には "Taro" (quotes for clarity), Hanako が勝つ場合には "Hanako" (quotes for clarity) と 1 行に出力せよ.

Sample Input 1

3
NNN
NNN
NNN

Sample Output 1

Taro

Sample Input 2

5
NNYNN
NNNNN
YNNNN
NNNNY
NNNYN

Sample Output 2

Hanako

Sample Input 3

8
NYNNNNNN
YNNYNNYN
NNNNNNNY
NYNNNNYN
NNNNNNNN
NNNNNNNN
NYNYNNNN
NNYNNNNN

Sample Output 3

Taro

Solution in Ruby (judge verdict: Wrong Answer)

module SimpleUndirectedGraphic
    require 'set'

    def each_connected_component(&block)
        return enum_for(__method__) unless block_given?
        reached = Set.new
        each_node do |s|
            next if reached.include?(s)
            cc = Set[s]
            queue = [s]
            until queue.empty?
                u = queue.shift
                each_neighbour(u) do |v|
                    next if cc.include?(v)
                    cc << v
                    queue << v
                end
            end
            block.call(cc)
            reached += cc
        end
    end

    def connected_components
        each_connected_component.to_a
    end
end

class Hash
    include SimpleUndirectedGraphic
    alias each_node each_key
    def each_neighbour(u)
        self[u].each do |v|
            yield(v)
        end
    end
end

n = gets.to_i

if n == 2
    puts 'Hanako'
    exit
end

g = {}
(0..n-1).map {|i| g[i] = Set.new}

a = (1..n).map { gets.chomp }
m = 0
(0..n-1).each do |u|
    (0..u-1).each do |v|
        if a[u][v] == ?Y
            m += 1
            g[u] << v
            g[v] << u
        end
    end
end

if n == 3
    puts m == 0 ? 'Taro' : 'No'
    exit
end

even_cc = odd_cc = 0
g.connected_components.each do |cc|
    if cc.size.even?
        even_cc += 1
    else
        odd_cc += 1
    end
end

#p m
#p g.connected_components
#p [odd_cc, even_cc]

if m.even?
    if even_cc == 0 && odd_cc == 2
        puts 'Hanako'
    elsif even_cc + odd_cc == 2
        puts 'Taro'
    elsif even_cc >= 1
        puts 'Taro'
    elsif (odd_cc + even_cc).odd?
        puts 'Taro'
    else
        puts 'Hanako'
    end
else
    if even_cc == 0 && odd_cc == 2
        puts 'Taro'
    elsif even_cc + odd_cc == 2
        puts 'Hanako'
    elsif even_cc >= 2
        puts 'Hanako'
    elsif (odd_cc + even_cc).even?
        puts 'Hanako'
    else
        puts 'Taro'
    end
end