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

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

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

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

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

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

b.y = k
k.p = b
n.p = b
assert n.p.y.p.txt == "b"