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

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

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

class D:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

g = A("g")
i = B("i")
h = C("h")
d = D("d")
b = C("b")
a = C("a")

g.q = i
g.w = i
g.s = d
i.s = b
i.x = d
i.u = g
h.u = b
h.p = b
d.v = h
b.u = h
b.p = a
a.u = h
a.p = h
assert b.p.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.w: B = None
        self.s: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

g = A("g")
i = B("i")
h = C("h")
d = D("d")
b = C("b")
a = C("a")

g.q = i
g.w = i
g.s = d
i.s = b
i.x = d
i.u = g
h.u = b
h.p = b
d.v = h
b.u = h
b.p = a
a.u = h
a.p = h
assert b.p.u.u.txt == "b"