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

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

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

d = A("d")
j = B("j")
k = C("k")
a = B("a")
e = A("e")
i = C("i")
m = B("m")
g = B("g")
f = C("f")
n = B("n")

d.p = e
d.w = f
j.s = d
j.p = i
k.r = g
k.s = i
a.s = d
a.p = i
e.p = d
e.w = f
i.r = m
i.s = k
m.s = d
m.p = f
g.s = e
g.p = f
f.r = a
f.s = k
n.s = e
n.p = f
assert n.p.s.s.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.w: C = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
k = C("k")
a = B("a")
e = A("e")
i = C("i")
m = B("m")
g = B("g")
f = C("f")
n = B("n")

d.p = e
d.w = f
j.s = d
j.p = i
k.r = g
k.s = i
a.s = d
a.p = i
e.p = d
e.w = f
i.r = m
i.s = k
m.s = d
m.p = f
g.s = e
g.p = f
f.r = a
f.s = k
n.s = e
n.p = f
assert n.p.s.s.s.r.txt == "g"