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

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

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

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

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

b.o = j
a.q = b
a.r = j
k.s = j
k.r = a
k.x = g
j.x = b
g.s = j
g.r = a
g.x = k
assert b.o.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

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

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

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

b.o = j
a.q = b
a.r = j
k.s = j
k.r = a
k.x = g
j.x = b
g.s = j
g.r = a
g.x = k
assert b.o.x.o.x.txt == "b"