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

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

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

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

g.x = n
j.s = f
n.z = j
b.x = n
l.s = f
f.x = n
k.s = g
m.x = n
assert g.x.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

g.x = n
j.s = f
n.z = j
b.x = n
l.s = f
f.x = n
k.s = g
m.x = n
assert g.x.z.s.txt == "f"