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

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

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

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

f = A("f")
b = B("b")
l = C("l")
d = D("d")
h = B("h")
g = A("g")
m = D("m")
c = D("c")
e = C("e")
a = D("a")

f.x = e
b.v = e
b.p = d
b.o = m
l.z = c
d.w = g
h.v = l
h.p = a
h.o = c
g.x = e
m.w = f
c.w = f
e.z = d
a.w = g
assert b.p.w.x.z.w.x.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

f = A("f")
b = B("b")
l = C("l")
d = D("d")
h = B("h")
g = A("g")
m = D("m")
c = D("c")
e = C("e")
a = D("a")

f.x = e
b.v = e
b.p = d
b.o = m
l.z = c
d.w = g
h.v = l
h.p = a
h.o = c
g.x = e
m.w = f
c.w = f
e.z = d
a.w = g
assert b.p.w.x.z.w.x.z.w.txt == "g"