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

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

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

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

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

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

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

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

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

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

k.p = a
k.q = m
f.q = m
f.w = m
a.y = k
a.w = k
a.r = m
a.p = m
m.x = a
m.o = a
m.z = f
assert k.p.y.p.r.txt == "m"