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

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

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

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

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

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

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

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

h.u = j
h.p = a
h.w = e
e.w = h
e.r = j
a.q = j
j.q = a
k.u = j
k.p = a
k.w = e
assert a.q.q.q.txt == "j"