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

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

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

f = A("f")
h = B("h")
d = C("d")
m = C("m")
a = B("a")

f.q = d
h.p = a
h.v = a
h.w = a
d.x = m
d.z = m
d.q = f
m.x = d
m.z = d
m.q = f
a.p = h
a.v = h
a.w = h
assert a.w.w.w.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

f = A("f")
h = B("h")
d = C("d")
m = C("m")
a = B("a")

f.q = d
h.p = a
h.v = a
h.w = a
d.x = m
d.z = m
d.q = f
m.x = d
m.z = d
m.q = f
a.p = h
a.v = h
a.w = h
assert a.w.w.w.v.v.txt == "h"