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

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

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

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

n = A("n")
f = B("f")
a = C("a")
h = D("h")
m = C("m")
i = A("i")
b = D("b")

n.x = f
n.u = h
n.p = a
n.v = m
f.x = h
f.p = m
a.r = n
a.o = f
h.q = a
h.w = a
h.p = b
h.s = m
m.r = i
m.o = f
i.x = f
i.u = b
i.p = a
i.v = a
b.q = a
b.w = m
b.s = m
b.p = h
assert a.o.p.o.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: D = None
        self.p: C = None
        self.v: C = None
        self.txt = txt

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

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

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

n = A("n")
f = B("f")
a = C("a")
h = D("h")
m = C("m")
i = A("i")
b = D("b")

n.x = f
n.u = h
n.p = a
n.v = m
f.x = h
f.p = m
a.r = n
a.o = f
h.q = a
h.w = a
h.p = b
h.s = m
m.r = i
m.o = f
i.x = f
i.u = b
i.p = a
i.v = a
b.q = a
b.w = m
b.s = m
b.p = h
assert a.o.p.o.p.o.txt == "f"