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

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

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

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

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

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

k.y = d
n.y = d
d.y = n
assert n.y.y.y.txt == "d"