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

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

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

a = A("a")
g = B("g")
f = C("f")
j = A("j")
n = B("n")

a.w = j
g.z = f
g.p = f
f.y = a
f.u = j
j.w = a
n.z = f
n.p = f
assert f.u.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

a = A("a")
g = B("g")
f = C("f")
j = A("j")
n = B("n")

a.w = j
g.z = f
g.p = f
f.y = a
f.u = j
j.w = a
n.z = f
n.p = f
assert f.u.w.w.txt == "j"