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

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

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

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

f = A("f")
e = B("e")
b = C("b")
k = D("k")
g = C("g")
i = A("i")
h = D("h")

f.p = b
e.o = i
e.y = h
e.v = f
b.u = e
b.q = e
b.r = g
b.t = f
k.z = g
g.u = e
g.q = e
g.r = b
g.t = i
i.p = g
h.z = g
assert h.z.q.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

f = A("f")
e = B("e")
b = C("b")
k = D("k")
g = C("g")
i = A("i")
h = D("h")

f.p = b
e.o = i
e.y = h
e.v = f
b.u = e
b.q = e
b.r = g
b.t = f
k.z = g
g.u = e
g.q = e
g.r = b
g.t = i
i.p = g
h.z = g
assert h.z.q.o.p.txt == "g"