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

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

j = A("j")
h = B("h")
b = A("b")
c = B("c")
i = B("i")

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

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

j = A("j")
h = B("h")
b = A("b")
c = B("c")
i = B("i")

j.q = c
h.w = b
h.o = b
b.q = h
c.w = j
c.o = b
i.w = b
i.o = j
assert i.o.q.w.txt == "j"