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

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

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

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

e = A("e")
b = B("b")
d = C("d")
c = D("c")

e.p = d
e.q = d
b.z = c
d.r = b
c.v = b
assert d.r.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: C = None
        self.txt = txt

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

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

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

e = A("e")
b = B("b")
d = C("d")
c = D("c")

e.p = d
e.q = d
b.z = c
d.r = b
c.v = b
assert d.r.z.v.txt == "b"