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.y: B = None
        self.txt = txt

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

a.r = k
b.v = k
b.y = c
c.v = k
c.y = b
m.r = g
g.r = m
k.r = m
assert g.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.y: B = None
        self.txt = txt

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

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