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

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

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

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

k = A("k")
g = B("g")
m = C("m")
h = D("h")

k.o = h
k.q = h
k.z = m
g.p = m
m.p = g
h.z = g
assert m.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.q: D = None
        self.z: C = None
        self.txt = txt

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

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

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

k = A("k")
g = B("g")
m = C("m")
h = D("h")

k.o = h
k.q = h
k.z = m
g.p = m
m.p = g
h.z = g
assert m.p.p.p.txt == "g"