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

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

b = A("b")
f = B("f")
l = C("l")
d = D("d")

b.q = d
b.s = d
b.z = l
f.z = d
f.y = l
f.x = b
f.p = b
l.y = d
d.u = f
assert l.y.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.z: C = None
        self.s: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

b = A("b")
f = B("f")
l = C("l")
d = D("d")

b.q = d
b.s = d
b.z = l
f.z = d
f.y = l
f.x = b
f.p = b
l.y = d
d.u = f
assert l.y.u.z.u.txt == "f"