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

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

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

e = A("e")
f = B("f")
h = C("h")
a = C("a")
g = A("g")
d = B("d")
c = C("c")
l = B("l")
m = A("m")

e.r = g
f.p = g
f.s = d
f.w = l
h.r = e
h.y = a
h.z = l
a.r = e
a.y = c
a.z = l
g.r = m
d.p = g
d.s = l
d.w = f
c.r = m
c.y = a
c.z = l
l.p = g
l.s = d
l.w = d
m.r = e
assert h.z.p.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

e = A("e")
f = B("f")
h = C("h")
a = C("a")
g = A("g")
d = B("d")
c = C("c")
l = B("l")
m = A("m")

e.r = g
f.p = g
f.s = d
f.w = l
h.r = e
h.y = a
h.z = l
a.r = e
a.y = c
a.z = l
g.r = m
d.p = g
d.s = l
d.w = f
c.r = m
c.y = a
c.z = l
l.p = g
l.s = d
l.w = d
m.r = e
assert h.z.p.r.r.r.r.r.txt == "e"