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

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

class C:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.txt = txt

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

b = A("b")
i = B("i")
l = C("l")
e = D("e")
j = B("j")

b.z = l
b.q = j
i.q = e
l.x = b
l.p = b
e.r = j
j.q = e
assert l.p.z.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.q: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.txt = txt

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

b = A("b")
i = B("i")
l = C("l")
e = D("e")
j = B("j")

b.z = l
b.q = j
i.q = e
l.x = b
l.p = b
e.r = j
j.q = e
assert l.p.z.x.q.txt == "j"