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

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

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

c = A("c")
h = B("h")
e = C("e")
a = A("a")

c.v = a
c.q = e
h.u = c
h.v = c
e.z = a
a.v = c
a.q = e
assert a.q.z.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: C = None
        self.txt = txt

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

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

c = A("c")
h = B("h")
e = C("e")
a = A("a")

c.v = a
c.q = e
h.u = c
h.v = c
e.z = a
a.v = c
a.q = e
assert a.q.z.v.q.txt == "e"