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

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

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

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

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

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

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

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

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