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

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

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

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

m = A("m")
i = B("i")
f = C("f")
j = D("j")
n = D("n")
d = A("d")

m.s = j
m.r = j
i.x = n
i.z = m
f.u = m
j.v = i
n.v = i
d.s = j
d.r = n
assert d.s.v.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.r: D = None
        self.txt = txt

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

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

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

m = A("m")
i = B("i")
f = C("f")
j = D("j")
n = D("n")
d = A("d")

m.s = j
m.r = j
i.x = n
i.z = m
f.u = m
j.v = i
n.v = i
d.s = j
d.r = n
assert d.s.v.x.v.txt == "i"