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

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

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

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

l = A("l")
n = B("n")
g = C("g")
f = D("f")
j = A("j")
e = C("e")
m = B("m")

l.x = e
l.z = f
l.s = f
n.x = f
n.o = l
g.x = f
f.p = m
f.y = g
f.t = n
j.x = e
j.z = f
j.s = f
e.x = f
m.x = f
m.o = j
assert e.x.y.x.p.x.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.z: D = None
        self.s: D = None
        self.txt = txt

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

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

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

l = A("l")
n = B("n")
g = C("g")
f = D("f")
j = A("j")
e = C("e")
m = B("m")

l.x = e
l.z = f
l.s = f
n.x = f
n.o = l
g.x = f
f.p = m
f.y = g
f.t = n
j.x = e
j.z = f
j.s = f
e.x = f
m.x = f
m.o = j
assert e.x.y.x.p.x.p.x.txt == "f"