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

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

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

k = A("k")
c = B("c")
f = C("f")
d = A("d")
g = C("g")

k.s = g
k.t = d
c.z = d
f.r = g
f.p = c
d.s = f
d.t = k
g.r = f
g.p = c
assert k.s.p.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.t: A = None
        self.txt = txt

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

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

k = A("k")
c = B("c")
f = C("f")
d = A("d")
g = C("g")

k.s = g
k.t = d
c.z = d
f.r = g
f.p = c
d.s = f
d.t = k
g.r = f
g.p = c
assert k.s.p.z.s.txt == "f"