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

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

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

f = A("f")
j = B("j")
k = C("k")
a = A("a")
d = B("d")

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

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

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

f = A("f")
j = B("j")
k = C("k")
a = A("a")
d = B("d")

f.r = d
f.t = k
f.s = j
j.r = f
j.p = f
k.s = a
k.z = a
a.r = j
a.s = j
a.t = k
d.r = a
d.p = f
assert k.z.t.s.txt == "a"