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

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

f = A("f")
e = B("e")
m = A("m")
d = A("d")
i = A("i")
c = B("c")

f.w = c
e.y = f
e.w = d
m.w = c
d.w = e
i.w = e
c.y = d
c.w = m
assert i.w.w.w.y.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.y: A = None
        self.w: A = None
        self.txt = txt

f = A("f")
e = B("e")
m = A("m")
d = A("d")
i = A("i")
c = B("c")

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