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

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

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

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

n = A("n")
j = B("j")
a = C("a")
b = D("b")
h = D("h")
m = A("m")
c = B("c")

n.y = c
j.o = a
a.q = j
a.p = j
a.x = n
b.p = a
b.w = c
h.p = a
h.w = j
m.y = c
c.o = a
assert a.p.o.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

n = A("n")
j = B("j")
a = C("a")
b = D("b")
h = D("h")
m = A("m")
c = B("c")

n.y = c
j.o = a
a.q = j
a.p = j
a.x = n
b.p = a
b.w = c
h.p = a
h.w = j
m.y = c
c.o = a
assert a.p.o.p.o.txt == "a"