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

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

f = A("f")
j = B("j")
e = A("e")
l = B("l")
n = A("n")
m = A("m")

f.r = l
j.r = l
j.x = f
e.r = j
l.r = j
l.x = e
n.r = j
m.r = j
assert j.x.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

f = A("f")
j = B("j")
e = A("e")
l = B("l")
n = A("n")
m = A("m")

f.r = l
j.r = l
j.x = f
e.r = j
l.r = j
l.x = e
n.r = j
m.r = j
assert j.x.r.r.txt == "j"