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

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

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

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

a = A("a")
c = B("c")
k = C("k")
g = D("g")
m = C("m")
f = B("f")

a.p = k
c.o = f
c.s = f
c.w = a
k.r = m
k.z = g
k.o = g
g.x = a
m.r = k
m.z = g
m.o = g
f.o = c
f.s = c
f.w = a
assert a.p.r.z.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

a = A("a")
c = B("c")
k = C("k")
g = D("g")
m = C("m")
f = B("f")

a.p = k
c.o = f
c.s = f
c.w = a
k.r = m
k.z = g
k.o = g
g.x = a
m.r = k
m.z = g
m.o = g
f.o = c
f.s = c
f.w = a
assert a.p.r.z.x.p.txt == "k"