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

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

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

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

d = A("d")
k = B("k")
c = C("c")
b = D("b")
j = A("j")

d.o = c
k.x = b
k.v = c
c.y = k
c.q = b
b.x = d
j.o = c
assert b.x.o.y.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

d = A("d")
k = B("k")
c = C("c")
b = D("b")
j = A("j")

d.o = c
k.x = b
k.v = c
c.y = k
c.q = b
b.x = d
j.o = c
assert b.x.o.y.v.q.txt == "b"