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

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

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

e = A("e")
m = B("m")
j = C("j")
i = B("i")
c = B("c")
b = B("b")
h = C("h")

e.p = h
m.w = h
m.p = e
m.q = e
j.r = i
i.w = h
i.p = e
i.q = e
c.w = j
c.p = e
c.q = e
b.w = h
b.p = e
b.q = e
h.r = b
assert h.r.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

e = A("e")
m = B("m")
j = C("j")
i = B("i")
c = B("c")
b = B("b")
h = C("h")

e.p = h
m.w = h
m.p = e
m.q = e
j.r = i
i.w = h
i.p = e
i.q = e
c.w = j
c.p = e
c.q = e
b.w = h
b.p = e
b.q = e
h.r = b
assert h.r.q.p.txt == "h"