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

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

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

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

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

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

n.w = b
n.r = b
k.y = n
k.r = h
h.y = n
h.r = k
b.w = n
b.r = n
assert b.w.r.w.r.txt == "b"