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.v: B = None
        self.txt = txt

a = A("a")
j = B("j")
e = B("e")
i = A("i")

a.u = i
a.r = j
j.v = e
e.v = j
i.u = a
i.r = e
assert a.r.v.v.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.v: B = None
        self.txt = txt

a = A("a")
j = B("j")
e = B("e")
i = A("i")

a.u = i
a.r = j
j.v = e
e.v = j
i.u = a
i.r = e
assert a.r.v.v.txt == "j"