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

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

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

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

d = A("d")
m = B("m")
a = C("a")
n = D("n")
f = A("f")

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

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

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

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

d = A("d")
m = B("m")
a = C("a")
n = D("n")
f = A("f")

d.y = n
m.p = n
m.q = n
m.o = a
m.x = a
a.o = n
a.y = n
a.x = f
n.y = m
n.q = m
n.r = m
f.y = n
assert f.y.q.p.y.txt == "m"