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

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

f = A("f")
c = B("c")
g = A("g")
i = A("i")
e = B("e")
k = B("k")
h = B("h")

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

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

f = A("f")
c = B("c")
g = A("g")
i = A("i")
e = B("e")
k = B("k")
h = B("h")

f.y = i
c.w = i
g.y = f
i.y = f
e.w = i
k.w = i
h.w = i
assert f.y.y.y.y.y.y.y.txt == "i"