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

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

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

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

h = A("h")
d = B("d")
c = C("c")
k = D("k")
b = D("b")
m = C("m")
i = B("i")

h.t = k
h.p = d
d.z = i
d.o = i
d.y = h
c.q = i
c.w = h
k.w = h
b.w = h
m.q = i
m.w = h
i.z = d
i.o = d
i.y = h
assert b.w.t.w.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.p: B = None
        self.txt = txt

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

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

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

h = A("h")
d = B("d")
c = C("c")
k = D("k")
b = D("b")
m = C("m")
i = B("i")

h.t = k
h.p = d
d.z = i
d.o = i
d.y = h
c.q = i
c.w = h
k.w = h
b.w = h
m.q = i
m.w = h
i.z = d
i.o = d
i.y = h
assert b.w.t.w.t.w.txt == "h"