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

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

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

k = A("k")
e = B("e")
h = C("h")
l = C("l")
j = B("j")

k.v = j
k.r = h
e.w = l
e.y = j
e.p = k
h.q = k
l.q = k
j.w = h
j.y = e
j.p = k
assert j.y.y.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.r: C = None
        self.txt = txt

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

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

k = A("k")
e = B("e")
h = C("h")
l = C("l")
j = B("j")

k.v = j
k.r = h
e.w = l
e.y = j
e.p = k
h.q = k
l.q = k
j.w = h
j.y = e
j.p = k
assert j.y.y.w.q.txt == "k"