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

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

j = A("j")
e = B("e")
c = A("c")
m = A("m")

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

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

j = A("j")
e = B("e")
c = A("c")
m = A("m")

j.u = m
j.r = e
e.u = m
e.s = m
c.u = j
c.r = e
m.u = c
m.r = e
assert m.r.u.u.txt == "c"