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

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

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

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

k.z = h
k.q = a
k.r = d
h.v = j
h.p = k
d.q = j
d.u = a
d.o = h
a.q = j
a.u = d
a.o = h
j.z = h
j.q = d
j.r = d
assert h.p.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: C = None
        self.r: C = None
        self.txt = txt

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

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

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

k.z = h
k.q = a
k.r = d
h.v = j
h.p = k
d.q = j
d.u = a
d.o = h
a.q = j
a.u = d
a.o = h
j.z = h
j.q = d
j.r = d
assert h.p.q.q.txt == "j"