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

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

l = A("l")
h = B("h")
c = A("c")
k = B("k")

l.v = c
l.r = h
h.v = k
h.s = l
c.v = l
c.r = h
k.v = h
k.s = l
assert k.v.s.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.r: B = None
        self.txt = txt

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

l = A("l")
h = B("h")
c = A("c")
k = B("k")

l.v = c
l.r = h
h.v = k
h.s = l
c.v = l
c.r = h
k.v = h
k.s = l
assert k.v.s.r.s.txt == "l"