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

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

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

m = A("m")
e = B("e")
h = C("h")
f = A("f")
i = A("i")
d = C("d")

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

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

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

m = A("m")
e = B("e")
h = C("h")
f = A("f")
i = A("i")
d = C("d")

m.v = i
e.z = h
e.r = h
e.t = d
h.t = d
h.s = e
f.v = m
i.v = m
d.t = h
d.s = e
assert i.v.v.v.v.v.v.txt == "i"