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

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

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

f = A("f")
n = B("n")
h = C("h")
a = B("a")
k = A("k")
d = C("d")

f.x = n
f.p = k
f.u = k
n.o = f
n.t = a
n.r = d
h.q = a
h.w = d
a.o = f
a.t = n
a.r = h
k.x = a
k.p = f
k.u = f
d.q = a
d.w = h
assert k.x.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: A = None
        self.u: A = None
        self.txt = txt

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

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

f = A("f")
n = B("n")
h = C("h")
a = B("a")
k = A("k")
d = C("d")

f.x = n
f.p = k
f.u = k
n.o = f
n.t = a
n.r = d
h.q = a
h.w = d
a.o = f
a.t = n
a.r = h
k.x = a
k.p = f
k.u = f
d.q = a
d.w = h
assert k.x.r.w.txt == "d"