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.q: A = None
        self.txt = txt

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

n.r = e
n.y = h
i.q = e
h.q = e
e.r = n
e.y = h
assert e.y.q.r.y.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.q: A = None
        self.txt = txt

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

n.r = e
n.y = h
i.q = e
h.q = e
e.r = n
e.y = h
assert e.y.q.r.y.txt == "h"