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

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

k = A("k")
d = B("d")
b = A("b")
l = B("l")
i = B("i")

k.x = b
d.v = l
d.s = k
b.x = k
l.v = i
l.s = b
i.v = d
i.s = k
assert d.s.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

k = A("k")
d = B("d")
b = A("b")
l = B("l")
i = B("i")

k.x = b
d.v = l
d.s = k
b.x = k
l.v = i
l.s = b
i.v = d
i.s = k
assert d.s.x.x.x.txt == "b"