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

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

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

l = A("l")
f = B("f")
n = C("n")
j = C("j")
g = B("g")
i = C("i")

l.w = f
f.s = i
f.r = i
f.z = l
n.w = j
j.w = n
g.s = i
g.r = j
g.z = l
i.w = j
assert i.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

l = A("l")
f = B("f")
n = C("n")
j = C("j")
g = B("g")
i = C("i")

l.w = f
f.s = i
f.r = i
f.z = l
n.w = j
j.w = n
g.s = i
g.r = j
g.z = l
i.w = j
assert i.w.w.w.txt == "j"