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

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

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

h = A("h")
m = B("m")
k = C("k")
j = B("j")
b = C("b")
a = C("a")
d = B("d")
g = A("g")
e = C("e")

h.x = k
m.r = j
m.y = j
m.x = a
k.s = d
j.r = d
j.y = d
j.x = e
b.s = j
a.s = j
d.r = j
d.y = j
d.x = a
g.x = b
e.s = d
assert d.y.y.r.r.r.x.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

h = A("h")
m = B("m")
k = C("k")
j = B("j")
b = C("b")
a = C("a")
d = B("d")
g = A("g")
e = C("e")

h.x = k
m.r = j
m.y = j
m.x = a
k.s = d
j.r = d
j.y = d
j.x = e
b.s = j
a.s = j
d.r = j
d.y = j
d.x = a
g.x = b
e.s = d
assert d.y.y.r.r.r.x.s.r.txt == "j"