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

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

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

g = A("g")
i = B("i")
b = C("b")
a = B("a")

g.v = b
i.r = g
i.q = b
i.y = a
b.r = a
a.r = g
a.q = b
a.y = i
assert i.q.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
b = C("b")
a = B("a")

g.v = b
i.r = g
i.q = b
i.y = a
b.r = a
a.r = g
a.q = b
a.y = i
assert i.q.r.r.txt == "g"