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.txt = txt

g = A("g")
b = B("b")
i = A("i")
h = B("h")
k = A("k")
c = B("c")
e = B("e")

g.r = k
b.v = k
i.r = k
h.v = k
k.r = i
c.v = i
e.v = k
assert b.v.r.r.r.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.txt = txt

g = A("g")
b = B("b")
i = A("i")
h = B("h")
k = A("k")
c = B("c")
e = B("e")

g.r = k
b.v = k
i.r = k
h.v = k
k.r = i
c.v = i
e.v = k
assert b.v.r.r.r.r.r.r.txt == "k"