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

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

k = A("k")
b = B("b")
c = A("c")
h = B("h")
f = A("f")
g = B("g")
e = A("e")
j = B("j")

k.x = e
k.p = e
b.q = c
c.x = e
c.p = f
h.q = f
f.x = e
f.p = k
g.q = e
e.x = k
e.p = c
j.q = c
assert g.q.p.p.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.txt = txt

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

k = A("k")
b = B("b")
c = A("c")
h = B("h")
f = A("f")
g = B("g")
e = A("e")
j = B("j")

k.x = e
k.p = e
b.q = c
c.x = e
c.p = f
h.q = f
f.x = e
f.p = k
g.q = e
e.x = k
e.p = c
j.q = c
assert g.q.p.p.x.x.x.txt == "e"