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

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

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

g = A("g")
a = B("a")
i = C("i")
c = B("c")
b = B("b")
k = B("k")
e = B("e")
m = C("m")

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

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

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

g = A("g")
a = B("a")
i = C("i")
c = B("c")
b = B("b")
k = B("k")
e = B("e")
m = C("m")

g.p = m
a.q = k
a.p = m
i.u = m
i.r = m
i.w = b
c.q = b
c.p = m
b.q = a
b.p = m
k.q = a
k.p = i
e.q = a
e.p = i
m.u = i
m.r = i
m.w = e
assert i.w.p.r.w.p.w.txt == "e"