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

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

b = A("b")
g = B("g")
c = B("c")
a = B("a")
k = A("k")

b.v = k
g.r = c
c.r = a
a.r = c
k.v = b
assert k.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

b = A("b")
g = B("g")
c = B("c")
a = B("a")
k = A("k")

b.v = k
g.r = c
c.r = a
a.r = c
k.v = b
assert k.v.v.v.v.txt == "k"