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

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

l = A("l")
i = B("i")
c = A("c")
g = B("g")
m = A("m")
d = B("d")
h = A("h")
f = A("f")

l.t = f
i.w = d
c.t = l
g.w = d
m.t = f
d.w = g
h.t = m
f.t = h
assert i.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

l = A("l")
i = B("i")
c = A("c")
g = B("g")
m = A("m")
d = B("d")
h = A("h")
f = A("f")

l.t = f
i.w = d
c.t = l
g.w = d
m.t = f
d.w = g
h.t = m
f.t = h
assert i.w.w.w.txt == "d"