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

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

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

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

a = A("a")
f = B("f")
h = C("h")
b = D("b")
l = A("l")
n = A("n")

a.q = f
a.r = f
a.p = b
a.o = l
f.q = b
f.w = b
f.o = b
f.y = h
h.r = n
b.q = a
l.q = f
l.r = f
l.p = b
l.o = n
n.q = f
n.r = f
n.p = b
n.o = a
assert f.q.q.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: D = None
        self.o: A = None
        self.r: B = None
        self.txt = txt

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

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

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

a = A("a")
f = B("f")
h = C("h")
b = D("b")
l = A("l")
n = A("n")

a.q = f
a.r = f
a.p = b
a.o = l
f.q = b
f.w = b
f.o = b
f.y = h
h.r = n
b.q = a
l.q = f
l.r = f
l.p = b
l.o = n
n.q = f
n.r = f
n.p = b
n.o = a
assert f.q.q.r.o.txt == "b"