class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.r: A = None
        self.txt = txt

n = A("n")
b = B("b")
h = B("h")
g = B("g")
j = A("j")
k = A("k")
d = A("d")

n.r = k
n.t = b
b.t = d
b.r = j
h.t = k
h.r = j
g.t = k
g.r = n
j.r = n
j.t = h
k.r = j
k.t = g
d.r = n
d.t = b
assert b.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.r: A = None
        self.txt = txt

n = A("n")
b = B("b")
h = B("h")
g = B("g")
j = A("j")
k = A("k")
d = A("d")

n.r = k
n.t = b
b.t = d
b.r = j
h.t = k
h.r = j
g.t = k
g.r = n
j.r = n
j.t = h
k.r = j
k.t = g
d.r = n
d.t = b
assert b.r.r.r.r.txt == "j"