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

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

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

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

g = A("g")
c = B("c")
j = C("j")
f = D("f")
i = D("i")

g.q = f
g.r = c
c.u = i
j.q = g
f.q = i
f.o = j
i.q = f
i.o = j
assert c.u.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.r: B = None
        self.txt = txt

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

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

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

g = A("g")
c = B("c")
j = C("j")
f = D("f")
i = D("i")

g.q = f
g.r = c
c.u = i
j.q = g
f.q = i
f.o = j
i.q = f
i.o = j
assert c.u.o.q.txt == "g"