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

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

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

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

m = A("m")
f = B("f")
l = C("l")
j = D("j")
h = D("h")
e = C("e")
i = B("i")

m.r = f
f.x = j
f.v = i
l.z = i
j.s = m
h.s = m
e.z = i
i.x = j
i.v = f
assert f.v.v.x.s.r.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

m = A("m")
f = B("f")
l = C("l")
j = D("j")
h = D("h")
e = C("e")
i = B("i")

m.r = f
f.x = j
f.v = i
l.z = i
j.s = m
h.s = m
e.z = i
i.x = j
i.v = f
assert f.v.v.x.s.r.x.s.txt == "m"