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

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

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

g = A("g")
i = B("i")
c = C("c")
f = C("f")
m = A("m")
d = B("d")
b = A("b")
e = C("e")

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

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

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

g = A("g")
i = B("i")
c = C("c")
f = C("f")
m = A("m")
d = B("d")
b = A("b")
e = C("e")

g.r = c
i.r = m
c.p = m
c.w = b
c.u = e
f.p = b
f.w = m
f.u = c
m.r = c
d.r = b
b.r = f
e.p = b
e.w = m
e.u = c
assert e.p.r.u.w.r.txt == "f"