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

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

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

i = A("i")
b = B("b")
e = C("e")
g = A("g")
h = C("h")
a = C("a")

i.q = e
i.p = g
b.u = h
e.w = b
e.y = b
e.t = g
g.q = a
g.p = i
h.w = b
h.y = b
h.t = g
a.w = b
a.y = b
a.t = i
assert i.p.p.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: A = None
        self.txt = txt

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

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

i = A("i")
b = B("b")
e = C("e")
g = A("g")
h = C("h")
a = C("a")

i.q = e
i.p = g
b.u = h
e.w = b
e.y = b
e.t = g
g.q = a
g.p = i
h.w = b
h.y = b
h.t = g
a.w = b
a.y = b
a.t = i
assert i.p.p.p.q.txt == "a"