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

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

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

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

m.p = g
m.w = f
f.p = e
f.r = a
i.o = f
i.p = f
i.q = m
h.p = g
h.w = g
d.o = g
d.q = h
d.p = f
e.o = f
e.q = m
e.p = g
g.p = j
g.r = a
b.o = f
b.q = a
b.p = g
j.o = f
j.q = h
j.p = g
a.p = f
a.w = f
assert i.p.r.w.r.p.p.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.w: B = None
        self.txt = txt

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

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

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

m.p = g
m.w = f
f.p = e
f.r = a
i.o = f
i.p = f
i.q = m
h.p = g
h.w = g
d.o = g
d.q = h
d.p = f
e.o = f
e.q = m
e.p = g
g.p = j
g.r = a
b.o = f
b.q = a
b.p = g
j.o = f
j.q = h
j.p = g
a.p = f
a.w = f
assert i.p.r.w.r.p.p.q.w.txt == "f"