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

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

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

f = A("f")
c = B("c")
k = C("k")
e = B("e")
h = B("h")
g = A("g")

f.t = c
f.x = g
f.z = k
c.p = h
c.r = h
c.q = e
k.r = g
e.p = c
e.r = c
e.q = h
h.p = c
h.r = c
h.q = e
g.t = h
g.x = f
g.z = k
assert k.r.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: A = None
        self.z: C = None
        self.txt = txt

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

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

f = A("f")
c = B("c")
k = C("k")
e = B("e")
h = B("h")
g = A("g")

f.t = c
f.x = g
f.z = k
c.p = h
c.r = h
c.q = e
k.r = g
e.p = c
e.r = c
e.q = h
h.p = c
h.r = c
h.q = e
g.t = h
g.x = f
g.z = k
assert k.r.t.p.txt == "c"