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

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

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

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

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

g.o = c
g.x = c
b.o = g
a.t = j
a.q = b
j.t = g
j.u = b
c.t = j
c.q = b
assert a.q.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.x: C = None
        self.txt = txt

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

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

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

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

g.o = c
g.x = c
b.o = g
a.t = j
a.q = b
j.t = g
j.u = b
c.t = j
c.q = b
assert a.q.o.o.txt == "c"