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

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

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

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

h = A("h")
f = B("f")
a = C("a")
m = D("m")
j = A("j")
g = D("g")
e = A("e")
b = A("b")

h.p = e
f.w = a
f.u = a
f.q = h
a.v = f
m.s = a
m.t = a
m.o = b
j.p = e
g.s = a
g.t = a
g.o = b
e.p = b
b.p = e
assert a.v.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

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

h = A("h")
f = B("f")
a = C("a")
m = D("m")
j = A("j")
g = D("g")
e = A("e")
b = A("b")

h.p = e
f.w = a
f.u = a
f.q = h
a.v = f
m.s = a
m.t = a
m.o = b
j.p = e
g.s = a
g.t = a
g.o = b
e.p = b
b.p = e
assert a.v.q.p.txt == "e"