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.p: B = None
        self.txt = txt

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

h.r = i
h.y = c
b.p = c
c.p = b
i.r = h
i.y = b
assert c.p.p.p.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.p: B = None
        self.txt = txt

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

h.r = i
h.y = c
b.p = c
c.p = b
i.r = h
i.y = b
assert c.p.p.p.txt == "b"