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

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

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

h = A("h")
g = B("g")
k = C("k")
j = C("j")
d = B("d")

h.o = j
h.p = k
h.q = k
g.w = h
k.w = d
k.v = d
k.y = h
j.w = d
j.v = d
j.y = h
d.w = h
assert g.w.o.y.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.p: C = None
        self.q: C = None
        self.txt = txt

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

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

h = A("h")
g = B("g")
k = C("k")
j = C("j")
d = B("d")

h.o = j
h.p = k
h.q = k
g.w = h
k.w = d
k.v = d
k.y = h
j.w = d
j.v = d
j.y = h
d.w = h
assert g.w.o.y.p.w.txt == "d"