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.t: B = None
        self.txt = txt

l = A("l")
i = B("i")
f = B("f")
m = B("m")
d = A("d")

l.w = f
i.y = l
i.t = m
f.y = l
f.t = m
m.y = d
m.t = i
d.w = m
assert d.w.t.y.w.t.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.t: B = None
        self.txt = txt

l = A("l")
i = B("i")
f = B("f")
m = B("m")
d = A("d")

l.w = f
i.y = l
i.t = m
f.y = l
f.t = m
m.y = d
m.t = i
d.w = m
assert d.w.t.y.w.t.txt == "m"