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

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

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

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

j = A("j")
n = B("n")
h = C("h")
g = D("g")
f = A("f")
c = B("c")

j.z = g
j.x = n
n.o = c
h.p = f
g.x = f
f.z = g
f.x = c
c.o = n
assert n.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.x: B = None
        self.txt = txt

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

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

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

j = A("j")
n = B("n")
h = C("h")
g = D("g")
f = A("f")
c = B("c")

j.z = g
j.x = n
n.o = c
h.p = f
g.x = f
f.z = g
f.x = c
c.o = n
assert n.o.o.o.o.o.txt == "c"