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

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

c = A("c")
g = B("g")
f = A("f")
e = A("e")
d = A("d")
k = B("k")
n = A("n")
m = A("m")
a = B("a")

c.x = a
g.v = m
g.q = c
f.x = a
e.x = k
d.x = k
k.v = c
k.q = m
n.x = g
m.x = g
a.v = d
a.q = c
assert g.q.x.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

c = A("c")
g = B("g")
f = A("f")
e = A("e")
d = A("d")
k = B("k")
n = A("n")
m = A("m")
a = B("a")

c.x = a
g.v = m
g.q = c
f.x = a
e.x = k
d.x = k
k.v = c
k.q = m
n.x = g
m.x = g
a.v = d
a.q = c
assert g.q.x.q.x.txt == "a"