class A:
    def __init__(self, txt: str):
        self.r: B = None
        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

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

i.r = j
i.t = j
n.q = h
n.o = i
j.q = i
j.o = h
h.r = n
h.t = n
assert h.t.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        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

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

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