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

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

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

class D:
    def __init__(self, txt: str):
        self.q: A = None
        self.y: C = None
        self.w: B = None
        self.v: C = None
        self.txt = txt

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

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

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

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

class D:
    def __init__(self, txt: str):
        self.q: A = None
        self.y: C = None
        self.w: B = None
        self.v: C = None
        self.txt = txt

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

f.z = l
l.r = a
l.y = a
d.p = a
d.s = a
a.q = f
a.y = d
a.v = d
a.w = l
assert l.r.y.s.v.txt == "d"