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

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

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

class D:
    def __init__(self, txt: str):
        self.w: A = None
        self.r: A = None
        self.z: A = None
        self.v: C = None
        self.txt = txt

f = A("f")
b = B("b")
d = C("d")
c = D("c")
k = D("k")

f.v = k
b.y = d
d.v = k
c.w = f
c.r = f
c.z = f
c.v = d
k.w = f
k.r = f
k.z = f
k.v = d
assert c.w.v.v.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.w: A = None
        self.r: A = None
        self.z: A = None
        self.v: C = None
        self.txt = txt

f = A("f")
b = B("b")
d = C("d")
c = D("c")
k = D("k")

f.v = k
b.y = d
d.v = k
c.w = f
c.r = f
c.z = f
c.v = d
k.w = f
k.r = f
k.z = f
k.v = d
assert c.w.v.v.v.r.txt == "f"