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

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

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

e = A("e")
c = B("c")
n = C("n")
m = A("m")
g = C("g")
b = B("b")

e.w = g
c.w = n
c.p = m
n.z = c
n.r = g
m.w = g
g.z = b
g.r = n
b.w = n
b.p = e
assert g.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

e = A("e")
c = B("c")
n = C("n")
m = A("m")
g = C("g")
b = B("b")

e.w = g
c.w = n
c.p = m
n.z = c
n.r = g
m.w = g
g.z = b
g.r = n
b.w = n
b.p = e
assert g.r.r.r.r.txt == "g"