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

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

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

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

h = A("h")
b = B("b")
f = C("f")
k = D("k")
m = A("m")

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

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

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

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

h = A("h")
b = B("b")
f = C("f")
k = D("k")
m = A("m")

h.p = m
h.s = f
h.o = f
h.z = b
b.r = k
b.p = k
b.x = m
f.p = h
k.w = b
k.r = f
m.p = h
m.s = f
m.o = f
m.z = b
assert m.z.x.z.txt == "b"