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

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

g = A("g")
h = B("h")
i = B("i")
j = B("j")
c = A("c")

g.r = c
h.v = g
h.s = j
i.v = g
i.s = j
j.v = c
j.s = h
c.r = g
assert g.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

g = A("g")
h = B("h")
i = B("i")
j = B("j")
c = A("c")

g.r = c
h.v = g
h.s = j
i.v = g
i.s = j
j.v = c
j.s = h
c.r = g
assert g.r.r.r.txt == "c"