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

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

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

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

f = A("f")
m = B("m")
g = C("g")
i = D("i")

f.r = g
m.v = i
g.s = f
i.w = g
i.x = g
i.z = m
assert g.s.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

f = A("f")
m = B("m")
g = C("g")
i = D("i")

f.r = g
m.v = i
g.s = f
i.w = g
i.x = g
i.z = m
assert g.s.r.s.txt == "f"