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

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.q: B = 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.p: D = None
        self.q: C = None
        self.w: C = None
        self.v: D = None
        self.txt = txt

f = A("f")
d = B("d")
m = C("m")
i = D("i")
l = D("l")
b = B("b")

f.x = d
d.w = i
d.q = b
m.r = f
i.p = l
i.v = l
i.q = m
i.w = m
l.p = i
l.v = i
l.q = m
l.w = m
b.w = l
b.q = d
assert b.q.w.p.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.q: B = 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.p: D = None
        self.q: C = None
        self.w: C = None
        self.v: D = None
        self.txt = txt

f = A("f")
d = B("d")
m = C("m")
i = D("i")
l = D("l")
b = B("b")

f.x = d
d.w = i
d.q = b
m.r = f
i.p = l
i.v = l
i.q = m
i.w = m
l.p = i
l.v = i
l.q = m
l.w = m
b.w = l
b.q = d
assert b.q.w.p.q.r.txt == "f"