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

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

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

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

b.r = h
b.q = c
g.x = a
g.w = d
h.z = c
k.r = c
k.q = c
c.z = h
a.x = g
a.w = b
d.r = h
d.q = c
assert b.r.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.q: C = None
        self.txt = txt

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

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

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

b.r = h
b.q = c
g.x = a
g.w = d
h.z = c
k.r = c
k.q = c
c.z = h
a.x = g
a.w = b
d.r = h
d.q = c
assert b.r.z.z.txt == "h"