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

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

class C:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: D = None
        self.u: B = None
        self.w: A = None
        self.txt = txt

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

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

l.q = f
f.z = k
f.t = k
f.q = k
f.w = l
k.r = f
k.u = f
k.p = d
k.w = l
d.y = f
assert l.q.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: D = None
        self.u: B = None
        self.w: A = None
        self.txt = txt

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

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

l.q = f
f.z = k
f.t = k
f.q = k
f.w = l
k.r = f
k.u = f
k.p = d
k.w = l
d.y = f
assert l.q.t.w.txt == "l"