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

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

l = A("l")
b = B("b")
i = B("i")
c = A("c")

l.q = i
l.p = b
b.z = l
i.z = l
c.q = i
c.p = i
assert l.q.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: B = None
        self.txt = txt

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

l = A("l")
b = B("b")
i = B("i")
c = A("c")

l.q = i
l.p = b
b.z = l
i.z = l
c.q = i
c.p = i
assert l.q.z.q.txt == "i"