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

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

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

f = A("f")
h = B("h")
e = C("e")
n = C("n")

f.q = e
f.u = e
f.v = h
h.p = n
h.q = f
h.z = f
e.w = h
e.z = f
n.w = h
n.z = f
assert n.w.q.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.v: B = None
        self.u: C = None
        self.txt = txt

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

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

f = A("f")
h = B("h")
e = C("e")
n = C("n")

f.q = e
f.u = e
f.v = h
h.p = n
h.q = f
h.z = f
e.w = h
e.z = f
n.w = h
n.z = f
assert n.w.q.v.q.txt == "f"