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

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

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

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

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

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

i.q = h
h.r = i
h.s = i
c.r = i
c.s = i
assert h.s.q.r.txt == "i"