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

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

e = A("e")
d = B("d")
i = B("i")
h = B("h")
j = A("j")
l = B("l")

e.r = j
e.x = h
d.r = j
i.r = j
h.r = e
j.r = e
j.x = h
l.r = j
assert e.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.x: B = None
        self.txt = txt

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

e = A("e")
d = B("d")
i = B("i")
h = B("h")
j = A("j")
l = B("l")

e.r = j
e.x = h
d.r = j
i.r = j
h.r = e
j.r = e
j.x = h
l.r = j
assert e.r.r.x.txt == "h"