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

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

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

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

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

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

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

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

i.t = b
g.u = b
g.p = b
g.w = f
b.x = g
m.t = b
f.u = b
f.p = b
f.w = g
d.t = b
assert f.w.w.u.x.w.txt == "f"