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

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

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

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

b = A("b")
a = B("a")
d = C("d")
c = D("c")
n = B("n")
g = D("g")

b.x = d
b.v = a
a.s = b
d.u = a
c.q = n
c.t = d
n.s = b
g.q = a
g.t = d
assert g.q.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.v: B = None
        self.txt = txt

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

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

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

b = A("b")
a = B("a")
d = C("d")
c = D("c")
n = B("n")
g = D("g")

b.x = d
b.v = a
a.s = b
d.u = a
c.q = n
c.t = d
n.s = b
g.q = a
g.t = d
assert g.q.s.x.txt == "d"