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

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

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

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

m = A("m")
g = B("g")
d = C("d")
k = D("k")

m.y = k
g.w = k
g.y = m
d.z = k
k.r = d
k.o = d
k.x = d
k.v = g
assert d.z.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

m = A("m")
g = B("g")
d = C("d")
k = D("k")

m.y = k
g.w = k
g.y = m
d.z = k
k.r = d
k.o = d
k.x = d
k.v = g
assert d.z.r.z.r.txt == "d"