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

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

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

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

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

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

h.q = a
i.o = h
a.o = h
assert h.q.o.q.txt == "a"