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

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

c = A("c")
d = B("d")
n = B("n")
l = A("l")

c.q = d
d.z = c
d.y = n
n.z = c
n.y = d
l.q = d
assert l.q.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

c = A("c")
d = B("d")
n = B("n")
l = A("l")

c.q = d
d.z = c
d.y = n
n.z = c
n.y = d
l.q = d
assert l.q.y.z.txt == "c"