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

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

a = A("a")
n = B("n")
i = A("i")
h = A("h")

a.r = i
a.y = n
n.o = i
i.r = a
i.y = n
h.r = a
h.y = n
assert h.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.y: B = None
        self.txt = txt

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

a = A("a")
n = B("n")
i = A("i")
h = A("h")

a.r = i
a.y = n
n.o = i
i.r = a
i.y = n
h.r = a
h.y = n
assert h.r.r.r.txt == "a"