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

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

class C:
    def __init__(self, txt: str):
        self.y: A = None
        self.v: D = None
        self.r: D = None
        self.txt = txt

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

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

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

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

class C:
    def __init__(self, txt: str):
        self.y: A = None
        self.v: D = None
        self.r: D = None
        self.txt = txt

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

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

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