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

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

h = A("h")
b = B("b")
a = B("a")
k = A("k")

h.s = k
h.r = k
b.y = h
b.u = a
a.y = h
a.u = b
k.s = h
k.r = h
assert h.r.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: A = None
        self.txt = txt

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

h = A("h")
b = B("b")
a = B("a")
k = A("k")

h.s = k
h.r = k
b.y = h
b.u = a
a.y = h
a.u = b
k.s = h
k.r = h
assert h.r.s.s.s.txt == "h"