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

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

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

b = A("b")
l = B("l")
m = C("m")
g = C("g")

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

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

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

b = A("b")
l = B("l")
m = C("m")
g = C("g")

b.r = l
b.z = l
b.o = g
l.v = m
l.t = b
l.q = g
m.q = b
m.r = b
g.q = b
g.r = b
assert l.q.r.o.r.txt == "b"