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

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

n = A("n")
l = B("l")
a = B("a")
h = A("h")
i = B("i")
d = B("d")
j = B("j")
c = A("c")

n.t = a
l.t = c
l.o = c
a.t = c
a.o = h
h.t = l
i.t = n
i.o = n
d.t = h
d.o = c
j.t = h
j.o = n
c.t = l
assert i.t.t.o.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

n = A("n")
l = B("l")
a = B("a")
h = A("h")
i = B("i")
d = B("d")
j = B("j")
c = A("c")

n.t = a
l.t = c
l.o = c
a.t = c
a.o = h
h.t = l
i.t = n
i.o = n
d.t = h
d.o = c
j.t = h
j.o = n
c.t = l
assert i.t.t.o.t.t.txt == "c"