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

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

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

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

c = A("c")
d = B("d")
e = C("e")
a = D("a")
j = D("j")
f = A("f")

c.o = d
c.u = f
d.w = e
d.s = c
e.q = d
a.s = j
j.s = a
f.o = d
f.u = c
assert c.u.o.s.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: A = None
        self.txt = txt

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

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

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

c = A("c")
d = B("d")
e = C("e")
a = D("a")
j = D("j")
f = A("f")

c.o = d
c.u = f
d.w = e
d.s = c
e.q = d
a.s = j
j.s = a
f.o = d
f.u = c
assert c.u.o.s.o.txt == "d"