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

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

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

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

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

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

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

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

e.s = d
e.y = d
e.x = d
h.r = i
i.v = a
i.y = j
i.r = m
m.r = i
j.v = e
j.y = i
j.r = d
d.r = i
a.s = m
a.y = m
a.x = h
assert j.r.r.r.r.y.v.txt == "e"