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

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

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

b = A("b")
j = B("j")
d = C("d")
k = C("k")
m = A("m")

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

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

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

b = A("b")
j = B("j")
d = C("d")
k = C("k")
m = A("m")

b.q = k
j.q = d
j.y = k
j.r = k
d.y = k
d.o = k
d.v = m
k.y = d
k.o = d
k.v = m
m.q = d
assert b.q.o.y.txt == "k"