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

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

l = A("l")
n = B("n")
i = A("i")
e = A("e")
d = B("d")
f = B("f")

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

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

l = A("l")
n = B("n")
i = A("i")
e = A("e")
d = B("d")
f = B("f")

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