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

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

g = A("g")
e = B("e")
l = A("l")
a = B("a")
m = A("m")
b = B("b")

g.z = b
e.s = b
l.z = e
a.s = e
m.z = b
b.s = a
assert l.z.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

g = A("g")
e = B("e")
l = A("l")
a = B("a")
m = A("m")
b = B("b")

g.z = b
e.s = b
l.z = e
a.s = e
m.z = b
b.s = a
assert l.z.s.s.txt == "a"