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

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

g = A("g")
l = B("l")
e = A("e")
a = A("a")
f = B("f")
i = B("i")

g.u = a
g.x = e
l.w = f
e.u = a
e.x = a
a.u = e
a.x = e
f.w = i
i.w = l
assert l.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.x: A = None
        self.txt = txt

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

g = A("g")
l = B("l")
e = A("e")
a = A("a")
f = B("f")
i = B("i")

g.u = a
g.x = e
l.w = f
e.u = a
e.x = a
a.u = e
a.x = e
f.w = i
i.w = l
assert l.w.w.w.w.w.txt == "i"