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

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

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

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

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

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

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

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

h.u = i
a.q = h
a.y = i
g.p = a
g.x = h
g.w = i
i.q = h
i.y = a
assert a.y.y.q.u.txt == "i"