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

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

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

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

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

k.r = b
k.q = d
f.o = k
f.w = k
f.s = m
b.q = k
h.p = f
h.u = m
h.w = k
m.p = d
m.u = h
m.w = k
d.o = k
d.w = k
d.s = h
assert b.q.r.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.q: B = None
        self.txt = txt

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

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

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

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

k.r = b
k.q = d
f.o = k
f.w = k
f.s = m
b.q = k
h.p = f
h.u = m
h.w = k
m.p = d
m.u = h
m.w = k
d.o = k
d.w = k
d.s = h
assert b.q.r.q.r.txt == "b"