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

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

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

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

b = A("b")
c = B("c")
k = C("k")
m = D("m")
a = A("a")
f = D("f")
h = D("h")

b.o = a
b.x = k
b.w = k
b.r = k
c.q = k
k.p = c
m.y = f
m.w = h
a.o = b
a.x = k
a.w = k
a.r = k
f.y = m
f.w = m
h.y = f
h.w = m
assert f.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.x: C = None
        self.w: C = None
        self.r: C = None
        self.txt = txt

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

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

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

b = A("b")
c = B("c")
k = C("k")
m = D("m")
a = A("a")
f = D("f")
h = D("h")

b.o = a
b.x = k
b.w = k
b.r = k
c.q = k
k.p = c
m.y = f
m.w = h
a.o = b
a.x = k
a.w = k
a.r = k
f.y = m
f.w = m
h.y = f
h.w = m
assert f.w.w.w.txt == "m"