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

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

d = A("d")
n = B("n")
l = B("l")
f = B("f")
j = A("j")
a = B("a")
c = A("c")
b = B("b")

d.p = c
d.t = b
n.x = j
n.q = j
l.x = j
l.q = j
f.x = j
f.q = c
j.p = d
j.t = b
a.x = j
a.q = j
c.p = d
c.t = a
b.x = d
b.q = d
assert c.p.t.q.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.t: B = None
        self.txt = txt

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

d = A("d")
n = B("n")
l = B("l")
f = B("f")
j = A("j")
a = B("a")
c = A("c")
b = B("b")

d.p = c
d.t = b
n.x = j
n.q = j
l.x = j
l.q = j
f.x = j
f.q = c
j.p = d
j.t = b
a.x = j
a.q = j
c.p = d
c.t = a
b.x = d
b.q = d
assert c.p.t.q.p.t.txt == "a"