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

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

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

h = A("h")
d = B("d")
g = C("g")
b = C("b")
c = C("c")

h.y = g
d.t = g
d.p = g
d.q = h
g.z = h
g.w = b
b.z = h
b.w = c
c.z = h
c.w = b
assert h.y.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

h = A("h")
d = B("d")
g = C("g")
b = C("b")
c = C("c")

h.y = g
d.t = g
d.p = g
d.q = h
g.z = h
g.w = b
b.z = h
b.w = c
c.z = h
c.w = b
assert h.y.w.w.txt == "c"