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

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

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

m = A("m")
j = B("j")
b = C("b")
k = A("k")
c = C("c")
g = C("g")

m.u = k
m.q = b
m.r = g
j.o = g
b.y = k
k.u = m
k.q = c
k.r = c
c.y = m
g.y = k
assert j.o.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.q: C = None
        self.r: C = None
        self.txt = txt

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

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

m = A("m")
j = B("j")
b = C("b")
k = A("k")
c = C("c")
g = C("g")

m.u = k
m.q = b
m.r = g
j.o = g
b.y = k
k.u = m
k.q = c
k.r = c
c.y = m
g.y = k
assert j.o.y.q.txt == "c"