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

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

k = A("k")
j = B("j")
c = A("c")
g = B("g")
i = B("i")
f = A("f")

k.w = c
j.z = g
j.y = i
c.w = f
g.z = i
g.y = j
i.z = j
i.y = j
f.w = c
assert f.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

k = A("k")
j = B("j")
c = A("c")
g = B("g")
i = B("i")
f = A("f")

k.w = c
j.z = g
j.y = i
c.w = f
g.z = i
g.y = j
i.z = j
i.y = j
f.w = c
assert f.w.w.w.w.txt == "f"