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

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

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

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

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

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

j.y = a
j.x = a
a.w = b
f.y = a
f.x = a
e.y = b
e.x = b
g.y = a
g.x = l
l.w = b
b.w = l
d.w = b
assert l.w.w.w.w.w.w.w.w.txt == "l"