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

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

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

k = A("k")
a = B("a")
m = C("m")
n = B("n")
b = C("b")
g = C("g")

k.s = g
a.s = k
a.r = k
a.z = m
m.w = g
m.r = n
n.s = k
n.r = k
n.z = m
b.w = g
b.r = a
g.w = b
g.r = n
assert k.s.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

k = A("k")
a = B("a")
m = C("m")
n = B("n")
b = C("b")
g = C("g")

k.s = g
a.s = k
a.r = k
a.z = m
m.w = g
m.r = n
n.s = k
n.r = k
n.z = m
b.w = g
b.r = a
g.w = b
g.r = n
assert k.s.r.s.txt == "k"