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

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

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

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

f = A("f")
c = B("c")
h = C("h")
e = D("e")
b = A("b")
j = C("j")
a = D("a")

f.r = h
f.p = j
f.v = a
f.t = e
c.p = b
c.o = e
h.o = f
h.q = b
e.p = b
e.r = h
b.r = j
b.p = j
b.v = e
b.t = a
j.o = b
j.q = b
a.p = b
a.r = h
assert b.r.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.p: C = None
        self.v: D = None
        self.t: D = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
h = C("h")
e = D("e")
b = A("b")
j = C("j")
a = D("a")

f.r = h
f.p = j
f.v = a
f.t = e
c.p = b
c.o = e
h.o = f
h.q = b
e.p = b
e.r = h
b.r = j
b.p = j
b.v = e
b.t = a
j.o = b
j.q = b
a.p = b
a.r = h
assert b.r.q.p.txt == "j"