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

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

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

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

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

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

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

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

k.q = a
k.r = g
k.v = m
m.r = a
g.o = b
b.q = m
b.v = m
b.r = g
a.r = m
i.q = m
i.r = g
i.v = a
assert b.r.o.r.txt == "g"