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

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

g = A("g")
a = B("a")
d = A("d")
e = B("e")
c = B("c")
l = B("l")

g.y = d
a.u = e
d.y = g
e.u = l
c.u = l
l.u = c
assert l.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

g = A("g")
a = B("a")
d = A("d")
e = B("e")
c = B("c")
l = B("l")

g.y = d
a.u = e
d.y = g
e.u = l
c.u = l
l.u = c
assert l.u.u.u.u.txt == "l"