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

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

a = A("a")
j = B("j")
n = A("n")
i = B("i")
h = B("h")

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

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

a = A("a")
j = B("j")
n = A("n")
i = B("i")
h = B("h")

a.t = h
j.q = a
j.o = n
n.t = h
i.q = a
i.o = n
h.q = n
h.o = a
assert a.t.o.t.o.txt == "a"