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

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

f = A("f")
d = B("d")
m = B("m")
n = A("n")
e = A("e")
k = B("k")
i = A("i")

f.y = k
d.w = n
m.w = e
n.y = k
e.y = d
k.w = f
i.y = d
assert f.y.w.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

f = A("f")
d = B("d")
m = B("m")
n = A("n")
e = A("e")
k = B("k")
i = A("i")

f.y = k
d.w = n
m.w = e
n.y = k
e.y = d
k.w = f
i.y = d
assert f.y.w.y.w.txt == "f"