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

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

d = A("d")
h = B("h")
j = A("j")

d.r = j
d.o = j
h.y = d
h.x = d
j.r = d
j.o = d
assert j.o.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.o: A = None
        self.txt = txt

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

d = A("d")
h = B("h")
j = A("j")

d.r = j
d.o = j
h.y = d
h.x = d
j.r = d
j.o = d
assert j.o.r.r.txt == "d"