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

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

l = A("l")
i = B("i")
g = A("g")
d = B("d")
j = B("j")
e = B("e")
f = A("f")

l.w = j
i.s = j
g.w = d
d.s = i
j.s = i
e.s = d
f.w = j
assert i.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

l = A("l")
i = B("i")
g = A("g")
d = B("d")
j = B("j")
e = B("e")
f = A("f")

l.w = j
i.s = j
g.w = d
d.s = i
j.s = i
e.s = d
f.w = j
assert i.s.s.s.s.s.s.txt == "i"