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

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

n = A("n")
e = B("e")
m = B("m")
g = B("g")
j = A("j")

n.u = j
e.s = m
m.s = e
g.s = m
j.u = n
assert g.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

n = A("n")
e = B("e")
m = B("m")
g = B("g")
j = A("j")

n.u = j
e.s = m
m.s = e
g.s = m
j.u = n
assert g.s.s.s.txt == "m"