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

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

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

j = A("j")
b = B("b")
d = C("d")
k = A("k")
g = B("g")

j.z = k
b.w = d
b.q = g
b.r = j
d.s = b
k.z = j
g.w = d
g.q = b
g.r = k
assert j.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

j = A("j")
b = B("b")
d = C("d")
k = A("k")
g = B("g")

j.z = k
b.w = d
b.q = g
b.r = j
d.s = b
k.z = j
g.w = d
g.q = b
g.r = k
assert j.z.z.z.z.z.txt == "k"