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

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

c = A("c")
n = B("n")
i = A("i")
b = A("b")
h = B("h")

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

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

c = A("c")
n = B("n")
i = A("i")
b = A("b")
h = B("h")

c.x = h
c.y = i
n.r = c
i.x = h
i.y = c
b.x = n
b.y = i
h.r = c
assert n.r.y.y.x.r.txt == "c"