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

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

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

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

h = A("h")
f = B("f")
n = C("n")
m = D("m")

h.y = n
h.z = m
h.s = f
f.r = m
n.s = h
n.z = h
n.p = f
n.v = f
m.t = f
assert h.z.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.z: D = None
        self.s: B = None
        self.txt = txt

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

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

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

h = A("h")
f = B("f")
n = C("n")
m = D("m")

h.y = n
h.z = m
h.s = f
f.r = m
n.s = h
n.z = h
n.p = f
n.v = f
m.t = f
assert h.z.t.r.txt == "m"