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

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

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

n = A("n")
j = B("j")
l = C("l")
f = C("f")
k = B("k")

n.z = l
n.y = k
j.u = n
j.t = n
j.w = k
l.x = f
l.y = n
l.p = n
f.x = l
f.y = n
f.p = n
k.u = n
k.t = n
k.w = j
assert k.t.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.y: B = None
        self.txt = txt

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

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

n = A("n")
j = B("j")
l = C("l")
f = C("f")
k = B("k")

n.z = l
n.y = k
j.u = n
j.t = n
j.w = k
l.x = f
l.y = n
l.p = n
f.x = l
f.y = n
f.p = n
k.u = n
k.t = n
k.w = j
assert k.t.z.x.txt == "f"