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

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

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

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

l = A("l")
k = B("k")
n = C("n")
j = D("j")
b = B("b")

l.x = k
k.y = j
n.p = j
j.y = l
j.q = k
b.y = j
assert j.y.x.y.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

l = A("l")
k = B("k")
n = C("n")
j = D("j")
b = B("b")

l.x = k
k.y = j
n.p = j
j.y = l
j.q = k
b.y = j
assert j.y.x.y.q.y.txt == "j"